ActionLink with parameter after ? instead of /
Please give me example how to generate ActionLink with reditection to: http://localhost/Articles?View=xx instead of http://localhost/Articles/View/xx ? Im doing this like as follow (and it's give me firs开发者_StackOverflowt type of redirection):
<%= Html.ActionLink("View this article", "View", "Articles", new { id = Model.Item.Slug }, null)%>
Just make sure that the id parameter does not map to a Route in Global.asax. Just change id to something else like recordId and change the action signature to use recordId and not id.
The default routes in the Global.asax are set up to match /{controller}/{action}/{id}. When you create the action link with the code above, you are telling MVC routing to set up a route where the controller is "Articles", the action is "View" and the id is "xxx".
The URL you are looking for is /Articles?View=xx. In this case, you are saying you aren't following the /{controller}/{action}/{id} paradigm. You should probably set up a static route in the global.asax as follows:
routes.MapRoute("Articles", //the name of the route
"Articles", // the URL you want to match
new { controller = "Articles", action = "Index" });
However, keep in mind that the routes are tested in the order they are set up, so you'll want this near the top of the list. You'll also want to test your other routes to make sure they aren't affected.
The code for your action link would then be
Html.ActionLink("View this article", "Index", "Articles", new { view = "xx" }, null)
精彩评论