开发者

Asp.net mvc3 Hash(#) handing in routing system

开发者 https://www.devze.com 2023-03-13 01:20 出处:网络
I use location.hash javascript mathod a lot at my ajax requests. Generally I replace standard {action}/{id} w开发者_开发技巧ith {action}#{id}

I use location.hash javascript mathod a lot at my ajax requests. Generally I replace standard {action}/{id} w开发者_开发技巧ith {action}#{id}

How can I introduce this strategy at rounting system? I wol like write:

 @Html.ActionLink(text, action, controller, new { id }, new { })

and this generates /controller/action#id ?

Oh may be it's not good idea? How do you process ajax requests(open some entity at list?)

Thanks


The answer you seek is here:

How to access AJAX hash values in ASP.NET MVC?

TL;DR - Its impossible.


Remember: Routing isn't just for generating links; it's also for parsing incoming URIs. Incoming URIs don't have hash/fragments on them, so the route you propose, if it were possible, wouldn't work for incoming requests.

You can write your own HTML helper, in lieu of Html.ActionLink to create the URI with the hash, if you want, but it can't be a route.


this should work as you want.

RedirectResult(Url.Action("{action}") + "#{id}");
0

精彩评论

暂无评论...
验证码 换一张
取 消