在cshtml或aspx/ascx中制作链接时,若参数可能是中文,则需要使用HttpUtility.UrlEncode():

@Html.Link("角色", "/SFC/Users/Users2Roles?user=" + HttpUtility.UrlEncode(User.Identity.Name))

而在对应的Action中,一切照常,不需要"Decode”(也有帖子说需要,但本人实验的结果是不需要):

public ActionResult Users2Roles(string user) { ViewBag.User = user; return View(SFCRoles.GetAllRoles()); } [HttpPost] public ActionResult Users2Roles(string user, FormCollection collection) { ViewBag.User = user; try { } }

此外还能解决类似空格和特殊字符的问题,比如当你想让一个页面关闭后回到另外一个页面,而另外一个页面的链接中偏偏有两个以上参加就,因此里边有个“&”,就可以:使用:

@Html.Link("x", "/SFC/Categories/Delete?rootID=" + root.ID + "&id=" + Model.ID, showInNewWindow:false, returnUrl: HttpUtility.UrlEncode(Request.Url.ToString()))

这个Html.Link是我自己编写的Helper,如果直接用a,也一样可以。