Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

MVC4 Different Redirection Techniques (Razor)

4.58/5 (13 votes)
25 Apr 2013CPOL 155.8K   2  
Different redirection techniques for MVC4

Introduction

This tip lists different redirection techniques for MVC4.

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)