Asp.net mvc3 Hash(#) handing in routing system
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}");
精彩评论