I’m using ASP.Net MVC 3 with the Razor engine.
I have an html helper that will be returning @Url.Action. The problem I’m running into is that the @Url.Action is not getting converted into a proper url. Instead the @Url.Action gets returned as part of the html.
It looks like the razor engine runs and then the html helpers run after the fact? That seems kind of backwards to me. Is there anything I can change so that my helper will run first?
Here is an example:
public static HtmlString Test(this HtmlHelper helper)
{
return new HtmlString("@Url.Action('Logoff', 'Login'");
}
In my _Layout.cshtml I have this..
@Html.Test()
And the html will show up as @Url.Action(‘Logoff’, ‘Login’)
Extending
UrlHelperseems more appropriate and natural when dealing with urls:And in your view: