如何在重写url后修复C#MVC中的白色sapce问题 [英] How do I fix white sapce problem in C# MVC after url rewriting

查看:110
本文介绍了如何在重写url后修复C#MVC中的白色sapce问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网址中,网址重写后现在显示:%E2%80%8B



产品/子类别/ 94 / Audi-50(86)-1.1 /空气过滤器/ 43420%E2%80%8B



应该是



产品/子类别/ 94 / Audi-50(86)-1.1 /空气滤清器/ 43420



我知道这是一个白色的空间,我试图解决这个问题,但没有任何问题成功。



我用这条路线:



 routes.MapRoute (
name: Detail
url: {controller} / {action} / {selected} / {category} / {code}
默认值: new {controller = Product,action = ProductDetails}
);





这是指向上述网址的href。

< a href =   @ Url.Action( ProductDetails   产品 ,new {code =@c.Code.Replace(  ,string.Empty),selected = @ selectedCar,category =@c.Name}) id =   link >  
详情
< / a >





我的尝试:



我试图用

 Trim()

来解决这个空白区问题尝试用

替换( %E2%80%8B string  .Empty)





我试过:



  string  encodedString = Server.HtmlEncode(code); 





这些都没有解决这个问题。你有什么其他的想法,我可以尝试更多,以解决这个问题?谢谢!

解决方案

你在问题​​中给出的网址有4个参数

产品/子类别/ 94 / Audi-50( 86)-1.1 /空气过滤器/ 43420

94-?

奥迪..-选择

空气过滤器 - 类别

code - 43420



你必须确保在参数中传递三个值。

但是

你可以尝试更多的东西

尝试1:添加其他可选参数条目



 routes.MapRoute(
name: Detail
url : {controller} / {action} / {selected} / {category} / {code}
默认值: new {controller = 产品,action = ProductDetails,selected = UrlParameter.Optional,category = UrlParameter.Optional,code = UrlParameter.Optional}
) ;





尝试2:按顺序分配参数

 <   a     href   =  @ Url.Action(  ProductDetails,   Product       new  < span class =code-attribute>   {   已选择  =   @ selectedCar,  category   =   @ c.Name, 代码  =   @ c.Code})    id   =   link >  
详情
< / a >


In my url, after url rewriting now appears this: %E2%80%8B

Product/SubCategories/94/Audi-50 (86)-1.1/Air filter/43420‌%E2%80%8B

It should be

Product/SubCategories/94/Audi-50 (86)-1.1/Air filter/43420‌

I know that this is somewhere a white space, I tried to resolve this, but without any success.

I use this route:

routes.MapRoute(
          name: "Detail",
          url: "{controller}/{action}/{selected}/{category}/{code}‌​",
          defaults: new { controller = "Product", action = "ProductDetails" }
      );



This is the href that points to the mentioned url.

<a href="@Url.Action("ProductDetails", "Product" , new { code=@c.Code.Replace(" ", string.Empty), selected=@selectedCar, category=@c.Name})" id="link">
 Details
</a>



What I have tried:

I've tried to resolve this white space problem with

Trim()

I've tried with

Replace("%E2%80%8B", string.Empty)



I've tried with:

string encodedString = Server.HtmlEncode(code);



None of these had fixed this problem. Do you have any other ideas what can I try more, in order to fix this problem? Thanks!

解决方案

the url which you have given in your question is having 4 parameters
Product/SubCategories/94/Audi-50 (86)-1.1/Air filter/43420‌
94-?
audi..- selected
air filter- category
code - 43420

you have to make sure you pass three values in parameter.
however
There are few more things which you can try
try 1: add the other optional parameters entry as well

routes.MapRoute(
          name: "Detail",
          url: "{controller}/{action}/{selected}/{category}/{code}‌​",
          defaults: new { controller = "Product", action = "ProductDetails", selected=UrlParameter.Optional,category = UrlParameter.Optional, code=UrlParameter.Optional }
      );



try 2: assign parameter in order

<a href="@Url.Action("ProductDetails", "Product" , new { selected=@selectedCar, category=@c.Name, code=@c.Code})" id="link">
 Details
</a>


这篇关于如何在重写url后修复C#MVC中的白色sapce问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆