How to URL encode parameters in ASP .NET MVC

前端 未结 3 1101
星月不相逢
星月不相逢 2020-12-04 01:52

I have the following code in my view:

<%= Html.ActionLink(
           \"View item\", 
           \"Index\", 
            \"Items\", 
            new 
             


        
3条回答
  •  遥遥无期
    2020-12-04 02:10

    I'm assuming you have a route setup and your url looks something like this:

    http://localhost/Items/Index/name%25with%25percent - (this will blow up)

    as opposed to this:

    http://localhost/Items/Index/?itemName=name%25with%25percent - (query string is ok)

    So an option would be to remove the "itemName" property from your route (in your RouteCollection) so that Html.ActionLink will render the Url using itemName as a QueryString parameter.

    As @Priyank says, the problem is because the itemName is part of the Url (not a QueryString parameter) and it contain illegal characters.

提交回复
热议问题