Skip to content

Instantly share code, notes, and snippets.

@RyannosaurusRex
Created August 6, 2013 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyannosaurusRex/6161247 to your computer and use it in GitHub Desktop.
Save RyannosaurusRex/6161247 to your computer and use it in GitHub Desktop.
Html.BeginForm will cause unwanted breaking of styling on most pages, particularly if you're placing it in a nav or similar area. This gist demonstrates how to move the Logout link, which in the ASP.NET MVC starter project is implemented using a form, to somewhere else on the page. We then fire it using some javascript in a link somewhere else o…
<!--
This javascript code will find the logout form on your page and do the submit.
We do this separation so we can have total control over styling.
-->
<a href="javascript:document.getElementById('logoutForm').submit()">Logout!</a>
<!--
Put this form anywhere you want outside your content area so styling isn't jacked up.
-->
@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-form pull-right" }))
{@Html.AntiForgeryToken()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment