2013-08-27 38 views
0

我的动作链接是提交工作不因特殊字符

<a href="@Url.Action("Edit", "UserProfile", new { id= Server.UrlEncode(item.UserCd) })"</a> 

样品ID =测试\西蒙

随着编码,我的URL看起来像这样

http://localhost/Home/UserProfile/Edit/Testing%5Simon 

它工作显示正常,但是当点击提交时,页面提示出HTTP错误404.0 - 未找到,我检查错误,它看到网络已经改变了它取数据的方式

Requested URL http://localhost:80/Home/UserProfile/Edit/Testing/Simon 

我不能够调试它,因为它从来没有去控制方法

如何应付这件事情?

+0

在你的山姆您是否指“测试/ Simon”或者是否确实将反斜杠改为正斜杠? – asymptoticFault

+0

是的,它将其改为正斜杠,不知道为什么,并使我的提交失败 – Se0ng11

+0

如果取出'Server.UrlEncode'并将ID设置为'item.UserCd',该怎么办? – asymptoticFault

回答

0

猜routeconfig是asp.net MVC的净

routes.MapRoute(
       name: "userProfile", 
       url: "UserProfile/Edit/{id}/{id1}", 
       defaults: new { controller = "UserProfile", action = "Edit", id = UrlParameter.Optional, id1 = UrlParameter.Optional } 
      ); 

我创建,因为这路线的主要核心,研究后,通过不同的例子,不知道这是正确的方式

我拿出从代码的编码和解码

<a href="@Url.Action("Edit", "UserProfile", new { id=item.UserCd })" ></a> 

它做工精细现在