c# - How to add a descriptive text to Html.ActionLink() url's -
given typical controller/action/id routing in mvc, looking add descriptive text url's of type
mysite.com/home/page/myarg/the-title-of-the-page-etc.
this similar they're of form
stackoverflow.com/questions/928349234/the-text-of-the-question-etc.
while can done with
html.actionlink(linktext, "page", new { id = "myarg" } ) + "/" + myurltext
looking existing extensions might available strip out non-alphanumeric characters etc. etc. before rolling out own
you don't want append text actionlink that. can accomplish want routing. add new route global.asax registerroutes method, above default route, so:
routes.maproute("page", "home/page/{id}/{title}", new { controller = "home", action = "page", id = urlparameter.optional, title = urlparameter.optional });
then set-up actionlink this:
@html.actionlink("sometext", "page", new { controller = "home", id = b.key, title = model.title})
Comments
Post a Comment