When creating a link in cshtml or aspx/ascx, if the parameter may be Chinese, you need to use httputility. urlencode ():
@ Html. Link ("role", "/SFC/users/users2roles? User = "+ httputility. urlencode (user. Identity. Name ))
In the corresponding action, everything is as usual and there is no "decode" (there are also posts saying yes, but I do not need the results of my experiments ):
Public actionresult users2roles (string user) {viewbag. user = user; return view (sfcroles. getallroles ();} [httppost] public actionresult users2roles (string user, formcollection collection) {viewbag. user = user; try {}}
In addition, it can solve the problem of space and special characters. For example, if you want to close a page and return to another page, but there are more than two links to the other page, therefore, if there is an "&" in it, you can: use:
@ Html. Link ("X", "/SFC/categories/delete? Rootid = "+ root. ID +" & id = "+ model. ID, showinnewwindow: false, returnurl: httputility. urlencode (request. url. tostring ()))
This html. link is a self-compiled helper. If you use a directly, the same is true.
But this write to write after all too long too much trouble, so if you often use returnurl please refer to my other post: http://blog.csdn.net/cheny_com/article/details/6544338 in the last few lines supplement. The two problems come together.
Refer:
Http://stackoverflow.com/questions/3101823/extract-chinese-text-from-query-string
Http://stackoverflow.com/questions/1380617/request-url-parameter
Http://stackoverflow.com/search? Q = Chinese + parameter + URL + Asp.net (all similar problems in stackoverflow)
Click to download the free agile development textbook: Martian agile development manual