How to URL encode parameters in ASP .NET MVC

前端 未结 3 1100
星月不相逢
星月不相逢 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:20

    Since these routedvalues are posted as part of URL string, they will be treated as separate values, separated by # and %. There are couple options for handle your case.

    You will have to implement your custom ValueProvider (IValueProvider and especially RouteDataValueProvider) to handle your custom need. One programmer had an issue with character '/' and he hacked it here http://mrpmorris.blogspot.com/2012/08/asp-mvc-encoding-route-values.html

    Second is to store values in TempData which persists across two request and use them.

    Hope this helps to think in right direction.

提交回复
热议问题