سؤال

I have declared custom routes similar to this: ASP.MVC routes without Details action

Here is my route:

routes.MapRoute(
    name: "Profile",
    url: "Profile/{aScreenName}",
    defaults: new { controller = "Profile", action = "Index", aScreenName = UrlParameter.Optional }
);

I thought this looked neater, but now I am struggling to find a way to create a hyperlink to these routes in Razor. The problem is everything I try wants an object and automatically tries to treat it as a full query string. I can't find the right helper to do this. I have tried @html, @url, and @href.

Does anybody know the best way to do this?

هل كانت مفيدة؟

المحلول

<a href="@Url.RouteUrl("Profile", new { aScreenName = "yourScreenName" })">click here</a>

or

@Html.ActionLink("click here", "Index", "Profile", new { aScreenName = "yourScreenName" })
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top