If you want to generate URLs for use in an MVC webpage for actions in your controller then the UrlHelper Action method is pretty handy. This can be embedded into your cshtml page and will generate a URL at runtime for the specified action which will be relative to where ever the site is running.

Index.cshtml

@model PendingApproval

<a class="btn btn-primary" href="@Url.Action("MyAction", "MyController", new { stepId = Model.StepId, control = Model.Control })" role="button">Approve</a>

There’s various overloads for this method and the code above is demonstrating calling a named action and controller and passing through two parameters called stepId and control which come from the view model.


Leave a Reply

Your email address will not be published. Required fields are marked *