I'm trying to extract some simple code into a separate helper function
@helper ShowPath()
{
<p class="migas">
<a href="@Url.Action("Index", "Home")">Home</a>
> <a href="@Url.Action("Index", "AboutUs")">About Us</a>
> Directory</p>
}
Works fine within the original cshtml file but the @Url.Action causes a compile error when I extract it to a separate file that I put within the App_Code folder.
Do I need to pass in a HTMLHelper from the calling page? If so, any ideas how?
A URL action is a hyperlink that points to a web page, file, or other web-based resource outside of Tableau. You can use URL actions to create an email or link to additional information about your data. To customize links based on your data, you can automatically enter field values as parameters in URLs.
There is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
Action(String, String, Object, String)Generates a fully qualified URL to an action method by using the specified action name, controller name, route values, and protocol to use.
you need to pass the UrlHelper
to your method
@helper ShowPath(UrlHelper url)
{
<p class="migas">
<a href="@Url.Action("Index", "Home")">Home</a>
> <a href="@url.Action("Index", "AboutUs")">About Us</a>
> Directory</p>
}
and then from a view,
@YouAppCodeName.ShowPath(Url)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With