MVC4 Different Redirection Techniques (Razor)


This tip lists different redirection techniques for MVC4.

  1. HTML Tag
    <input type="button" value="Forgot Password" 
    onclick="window.location.href('@Url.Action("ForgotPassword","Account")')" />
  2. For posting, you could use a form:
    <form method="post" id="signin" action="@Url.Action("ForgotPassword", "Account")">
    <input type="button" value="Forgot Password" />
  3. Using script:
    <script type="text/javascript">
        $(document).ready(function () {     
          $('#btnForgotPassword').click(function (e)      {
              location.href = '@Url.Content("~/Account/ForgotPassword/")';
    //change below input tag
    <input id='btnForgotPassword' type="button" value="Forgot Password" />
  4. If it is a link:
    @Html.ActionLink("some text", "actionName", "controllerName")
  5. For posting, use a form:
    @ using(Html.BeginForm("actionName", "controllerName")) { 
        <input type="submit" value="Some text" />
  6. For Anchor Tag:
    <a href="" class="Button">Text</a>
  7. Using RenderAction:
    @{ Html.RenderAction("ActionName", "ControllerName", 
    new { FranchiseSetId = Model.FranchiseSetID }); }

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: