Friday, October 11, 2013

Upgrade ASP .NET MVC 5 default layout to bootstrap 3

If you have started developing web applications with ASP .NET MVC 5 you might have noticed that it comes with bootstrap version 2 and the latest version 3. In order to upgrade the default template for version 3, you can use these files as a reference.

Right click solution -> Manage NuGet packages Updates -> Update bootstrap to version 3

<!DOCTYPE html>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    <div class="navbar navbar-default navbar-static-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" 
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                @Html.ActionLink("Application name", "Index", "Home", null, 
                    new { @class = "navbar-brand" })

            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li class="active">
                        @Html.ActionLink("Home", "Index", "Home")
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            Dropdown <b class="caret"></b>
                        <ul class="dropdown-menu">
                            <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li class="divider"></li>
                            <li class="dropdown-header">Nav header</li>
                            <li><a href="#">Separated link</a></li>
                            <li><a href="#">One more separated link</a></li>
            </div><!--/.nav-collapse -->
    <div class="container">
        <hr />
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>

    @RenderSection("scripts", required: false)

@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
    using (Html.BeginForm("LogOff", "Account", FormMethod.Post, 
          new { id = "logoutForm", @class = "navbar-form pull-right" }))
    <ul class="nav navbar-nav navbar-right">
            @Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", 
                 "Manage", "Account", routeValues: null, 
                 htmlAttributes: new { title = "Manage" })
        <li><a href="javascript:document.getElementById('logoutForm').submit()">
            Log off</a></li>
    <ul class="nav navbar-nav navbar-right">
        <li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, 
            htmlAttributes: new { id = "registerLink" })</li>
        <li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, 
            htmlAttributes: new { id = "loginLink" })</li>
*** Content/Site.css *** Remove padding-top from body

No comments:

Post a Comment