Click here to Skip to main content
15,885,985 members
Articles / Web Development / HTML
Tip/Trick

MVC4 Different Redirection Techniques (Razor)

Rate me:
Please Sign up or sign in to vote.
4.58/5 (13 votes)
25 Apr 2013CPOL 154.6K   33   3
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)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionSample one is not working Pin
Hendrawan Harjanto19-Jan-14 23:09
Hendrawan Harjanto19-Jan-14 23:09 
Generalnice collection Pin
the headless nick23-Jun-13 19:21
professionalthe headless nick23-Jun-13 19:21 
QuestionNice details Pin
rahuljosh007200028-Apr-13 14:33
rahuljosh007200028-Apr-13 14:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.