Click here to Skip to main content
15,907,905 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Greetings!
I am learning bootstrap. I have created a bootstrap template using layoutit.com . I want to understand what changes do I need to do in index.cshtml and _layout.cshtml to implement the created bootstrap template in my VS2015 MVC project.

Looking forward for an answer. Thank you.

What I have tried:

I have included css files in content folder and js files in script folder in my solution. I tried adding the html code provided by layoutit.com on creation of template to my index.schtml page but the pafe developed is scattered. I also tried adding css link in index.cshtml page like this:
<link href="~/css/bootstrap.css" rel="stylesheet" />

I have registered style and script bundle in bundleconfig.cs like this:
public class BundleConfig
   {
       public static void RegisterBundles(BundleCollection bundles)
       {
           StyleBundle(bundles);
           ScriptBundle(bundles);
       }

       public static void StyleBundle(BundleCollection bundles)
       {
           bundles.Add(new StyleBundle("~/css")
                    .Include("~/Content/bootstrap.css"));
       }

       public static void ScriptBundle(BundleCollection bundles)
       {
           bundles.Add(new ScriptBundle("~/js")
                    .Include("~/Scripts/jquery-1.10.2.js")
                    .Include("~/Scripts/bootstrap.js"));
       }
   }
Posted
Updated 10-Apr-17 21:55pm

Here is an example using bootstrap on a single page, the scripts and styles decoration shall be the same.

Bootstrap Menu[^]

I see your code has registered style and script bundle in bundleconfig.cs but did the layout page render it? Also, verify your styles and scripts location, make sure the files are in the correct location.
HTML
@Styles.Render("~/css")
@Scripts.Render("~/js")

I think this reference is wrong, should it be ~/Content/bootstrap.css?
HTML
<link href="~/css/bootstrap.css" rel="stylesheet" />
 
Share this answer
 
v2
The issue is resolved. I missed out the following part:
Go to Shared folder.Write the following code in the _Layout.cshtml -
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title - My ASP.NET MVC Application</title>
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/bootstrap-theme.min.css" rel="stylesheet" />

</head>
<body>

    <div class="container">
        @RenderBody()
    </div>

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/modernizr-2.6.2.js"></script>
    <script src="~/Scripts/respond.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
</body>
</html> 
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900