开发者

MVC2: Need to route Urls containing # symbol

I am looking for a way to correctly route urls that contain the '#' symbol. For such urls i basically want to ignore the #.

For example I want Stores/Index/#/{storeName} to route to the Index action of the Store controller passing a single parameter (storeName).

I have tried matching the literal '#' in the string but this is not working. (The action is called but the storeName parameter is not passed)

routes.MapRoute("RemoveHash", "Store/Index/#/{storeName}",
            new {controller = "Store", action = "Index", storeName = UrlParameter.Optional});

I have also tried having 2 parameters to the action (the first being the #), thinking that I could just ignore the # if it was passed (hacky i know)... but something goes wrong with the routing in this case and neither parameter is passed to the action.

I would like to avoid using a HttpHandler for this task, if I could开发者_高级运维 handle this using the MVC routing system that would be ideal.

Any suggestions?


What you are trying to do is impossible. Everything that follows the # (hash) sign in the URL is completely ignored when the browser sends a request to the server, so your ASP.NET MVC application could never get this value. Only client side javascript could read this value (using window.location.hash) and could pass it to the server using AJAX request and a normal URL (for example: Store/Index/{storeName}).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜