开发者

Why does the Action Link depend on the current request?

For example, when I visit http://www.nerddinner.com/Home/About/, the About tab points to http://www.nerddinner.com/Home/About/ which is what I expect.

However, If i were to visit http://www.nerddinner.com/Home/About/WhyDoesThisLinkChange, not only is this page valid but the About tab also points to http://www.nerddinner.com/Home/About/WhyDoesThisLinkChange. Why does ASP.NET MVC do this and how do i prevent it fr开发者_JS百科om doing it?


Can you show your routing setup? Something is wrong with it I'd suggest. The second example URL shouldn't map to the same action.

You probably have a parameter in the routing - and correctly MVC is preserving this parameter.

In principal if you have

/product/view/17

Controller = product

Action = view

{productId} = 17

So in this case it makes sense to preserve the Id of the product across requests to the same action.

But in your case you don't really want both those URLs to map to the same place. That said once you are there - with the second URL - it makes sense for MVC to use the same URL to get back to the same action.

UPDATE: If you want to explicitly stop a parameter being accepted for this URL then you need to make the parameter accepting routing option more specific so it excludes this URL, or put in a routing option above it without a parameter than accepts only the Home/About URL.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜