How to remove System.Web.Mvc.UrlParameter from url
I have an action link that looks like;
<%= Html.ActionLink(Model.forumItem.title, "ViewForumItem", new { Id = Model.forumItem.id, title=Model.forumItem.title.Replace(" ", "-") })%>
However the url it produces is;
http://localhost:开发者_如何学Go50756/Home/ViewForumItem/System.Web.Mvc.UrlParameter/Clappy?Id=15
What can I do to make it look like;
http://localhost:50756/Home/ViewForumItem/15/Clappy
Much like SO does?
add a Route Definition like this
routes.MapRoute(
"MyNewRoute", // Route name
"Home/{action}/{id}/{title}",
new { controller = "Home", action = "Index", id = "", title = "" } // Parameter defaults
);
make sure of your parameter keys in your ActionLink does exist in your Route Definition and in the same case since it is a case sensitive for example the id
must have small case if you write it in small case in your Route Definition.
精彩评论