HTML页面丢失CSS,在asp.net mvc5中布局

时间:2016-04-08 15:54:55

标签: asp.net-mvc html5 css3 layout

晚上好,大家好,我希望每个人都有一个愉快的和平日,

我目前正在开发一个Web应用程序(asp.net mvc 5) 我创建了一个包含菜单的布局和所有这些(见图(1))

see an example of this in action here

但是当我点击(“CréerAO”)时

 <li>
      <a href="@Url.Action("Create","AppelOffre")"><i class="fa fa-fw fa-floppy-o"></i> Créer AO</a>
  </li>

当重定向发生时,页面失去了它的风格(css)   (见图(2))

image(1)

我的布局代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">



    <title>@ViewBag.Title</title>
    <!--
    <link rel="SHORTCUT ICON" href="~/img/home.ico" />-->
    <link rel="icon" href="@Url.Content("~/img/logo.ico")"/>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="css/sb-admin.css" rel="stylesheet">
    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->


    <!--  Style pour HOVER main pour les balises " <a> "   -->
    <style type="text/css">
        a
        {
            cursor: pointer;
        }
    </style>


</head>
<body>
    <div id="wrapper">
        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand">CHU Service des Marchés</a>
            </div>
            <!-- Top Menu Items -->
            <ul class="nav navbar-right top-nav">                                
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> John Smith <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="#"><i class="fa fa-fw fa-power-off"></i> Déconnection</a>
                        </li>
                    </ul>
                </li>
            </ul>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <ul class="nav navbar-nav side-nav">
                    <li>
                        <a href="/Index/Index"><i class="fa fa-fw fa-home"></i> Acceuil</a>
                    </li>

                    <!--  Menu APPEL D'OFFRE ------------------------------------------------------------------------------------------------- -->
                    <li>
                        <a data-toggle="collapse" data-target="#demo-appel"><i class="fa fa-fw fa-tasks"></i> Appel d'Offre <i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo-appel" class="collapse">

                            <li>
                                <a href="@Url.Action("Create","AppelOffre")"><i class="fa fa-fw fa-floppy-o"></i> Créer AO</a>
                            </li>
                            <li>
                                <a href="#"><i class="fa fa-fw fa-list"></i> Liste des AO</a>
                            </li>
                            <li>
                                <a href="#"><i class="fa fa-fw fa-search"></i> Recherche AO</a>
                            </li>

                        </ul>
                    </li>
                    <!--  --------------------------------------------------------------------------------------------------------------  -->

                    <!--  Menu CONCURRENT ------------------------------------------------------------------------------------------------- -->
                    <li>
                        <a data-toggle="collapse" data-target="#demo-concu"><i class="fa fa-fw fa-users"></i> Concurrent <i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo-concu" class="collapse">
                            
                            <li>
                                <a href="#"><i class="fa fa-fw fa-floppy-o"></i> Créer Concurrent</a>
                            </li>
                            
                            <li>
                                <a href="#"><i class="fa fa-fw fa-list"></i> Liste des Concurrents</a>
                            </li>

                            <li>
                                <a href="#"><i class="fa fa-fw fa-search"></i> Rechercher Concurrent</a>
                            </li>

                        </ul>
                    </li>
                    <!--  --------------------------------------------------------------------------------------------------------------  -->
                    

                    <!--  Menu LOTS ------------------------------------------------------------------------------------------------- -->
                    <li>
                        <a data-toggle="collapse" data-target="#demo-lot"><i class="fa fa-fw fa-archive"></i> Lots <i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo-lot" class="collapse">

                            <li>
                                <a href="#"><i class="fa fa-fw fa-floppy-o"></i> Créer Lot</a>
                            </li>

                            <li>
                                <a href="#"><i class="fa fa-fw fa-list"></i> Consultation des Lot</a>
                            </li>

                            <li>
                                <a href="#"><i class="fa fa-fw fa-search"></i> Rechercher Lot</a>
                            </li>

                        </ul>
                    </li>
                    <!--  --------------------------------------------------------------------------------------------------------------  -->



                    <!--  Menu Article ------------------------------------------------------------------------------------------------- -->
                    <li>
                        <a data-toggle="collapse" data-target="#demo-article"><i class="fa fa-fw fa-medkit"></i> Article <i class="fa fa-fw fa-caret-down"></i></a>
                        <ul id="demo-article" class="collapse">

                            <li>
                                <a href="#"><i class="fa fa-fw fa-floppy-o"></i> Créer Article</a>
                            </li>

                            <li>
                                <a href="#"><i class="fa fa-fw fa-list"></i> Liste des Articles</a>
                            </li>

                            <li>
                                <a href="#"><i class="fa fa-fw fa-search"></i> Rechercher Article</a>
                            </li>

                        </ul>
                    </li>
                    <!--  --------------------------------------------------------------------------------------------------------------  -->


                    <li>
                        <a><i class="fa fa-fw fa-money"></i> Estimation</a>
                    </li>
                    
                   
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </nav>
        <div id="page-wrapper">
            <div class="container-fluid">
                <!-- Page Heading -->
                <div class="row">
                    <div class="col-lg-12">
                        <h2 class="page-header">
                            @ViewBag.Page
                        </h2>
                        <div>
                            @RenderBody()
                        </div>
                    </div>
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </div>
        <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->
    <!-- jQuery -->
    <script src="js/jquery.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
</body>
</html>

我的(CreateAO页面)

@{
    ViewBag.Title = "Créer Appel d'Offre";
    ViewBag.Page = "Création d'un Nouveau Appel d'Offre";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<body>
    <form class="form-horizontal">
        <div class="form-group">
            <label for="designation" class="col-sm-2 control-label">Désignation</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="designation" placeholder="Désignation d'Appel d'Offre">
            </div>
        </div>
        <div class="form-group">
            <label for="DateOuverture" class="col-sm-2 control-label">Date d'Ouverture</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="DateOuverture" placeholder="Date Ouverture">
            </div>
        </div>
        
        <div class="form-group">
            <label for="Datefermeture" class="col-sm-2 control-label">Date de Fermeture</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="Datefermeture" placeholder="Date Ouverture">
            </div>
        </div>

        <div class="form-group">
            <label for="Datefermeture" class="col-sm-2 control-label">Jugement</label>
            <div class="col-sm-10">
                <input type="checkbox" class="form-control" id="Echantillon"> Echantillon
                <input type="checkbox" class="form-control" id="Document"> Document
            </div>
        </div>



    </form>
</body>

问题:不是在进入(@RenderBody)的页面中共享的布局CSS

注意:请不要介意我的英语,这不是那么好。

提前完成

1 个答案:

答案 0 :(得分:3)

替换

<link href="css/bootstrap.min.css" rel="stylesheet">

<link href="~/css/bootstrap.min.css" rel="stylesheet">

假设您的css目录位于Web项目的根目录。

razor会将~ tilda )转换为应用根的相对网址,这样无论您在哪个页面,它都会始终有效。