Wednesday, May 14, 2014

MVC Different Redirection Techniques (Razor)


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" />
    </form>
       
  3. Using script:
    <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.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="http://www.codeproject.com/Controller/View" class="Button">Text</a>
       
  7. Using RenderAction:
    @{ Html.RenderAction("ActionName", "ControllerName", 
    new { FranchiseSetId = Model.FranchiseSetID }); }
      
http://www.codeproject.com/Articles/429164/Html-BeginForm-vs-Ajax-BeginForm-in-MVC

 Different ways for returning/rendering a view in MVC Razor

http://www.dotnet-tricks.com/Tutorial/mvc/4XDc110313-return-View()-vs-return-RedirectToAction()-vs-return-Redirect()-vs-return-RedirectToRoute().html

http://www.codeproject.com/Tips/583469/MVC-Different-Redirection-Techniques-Razor

http://www.dotnet-tricks.com/Tutorial/csharp/c4SE281212-Difference-between-Response.Redirect-and-Server.Transfer.html

No comments:

Post a Comment