![](/img/trans.png)
[英]$ is undefined when loading a MVC 5 project in Visual Studio 2015
[英]CSS not loading because of div in Visual Studio MVC
我使用的是Visual Studio 2013 MVC,我的_Layout有一個模板,所有腳本都已加載到我的視圖索引中,在_layout中,我有一個導航欄,該導航欄應該有一個使用大量消息的下拉菜單css和js。
當我將消息作為局部視圖加載時,一切正常,但是當我嘗試使用JQuery自行重新加載數據時,我必須將它放在div中。 這樣做打破了所有的風格,就像沒有Css一樣,我也嘗試過改變父div的id,這也打破了風格。 我正在使用AdminLTE 2。
例子:
當它是這樣的,它的工作原理
<li class="dropdown notifications-menu">
<!-- Menu toggle button -->
@Html.Action("Notifications", "Home")
</li>
只是將其更改為此會破壞樣式
<li class="dropdown notifications-menu">
<!-- Menu toggle button -->
<div>
@Html.Action("Notifications", "Home")
</div>
</li>
此外,這是我重新加載該部分的方式
<script>
window.onload = function () {
refreshNotifications();
}
function refreshNotifications() {
console.log("Reload...");
$.ajax({
url: 'Home/Notifications',
type: 'get',
success: function(result) {
//$("#partialsgpthing").html(result);
// $("#navbar").html(result);
}
});
setTimeout('refreshNotifications()', 30000);
}
</script>
我在控制器中使用public PartialViewResult Notifications()
局部視圖是這樣的:
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<span class="label label-warning">@ViewBag.Notifications</span>
</a>
<ul class="dropdown-menu">
<li class="header">Tiene @ViewBag.Notifications notificaciones</li>
<li>
<!-- Inner Menu: contains the notifications -->
<ul class="menu" style=" max-height: 200px; margin: 0; padding: 0; list-style: none; overflow-x: hidden;">
@foreach (string notification in ViewBag.NotificationMsgs) {
<li>
@{string[] detail = notification.Split('|');}
<!-- start notification -->
<a href="@detail[8]">
<i class="fa @detail[3] @detail[4]"></i> @detail[5]<br />@detail[2]
</a>
</li>
}
<!-- end notification -->
</ul>
</li>
<li class="footer"><a href="#">Ver todas</a></li>
</ul>
如何使樣式起作用或使用其他方法不斷重新加載該部分? 主要是任何不使用div的東西都會起作用。
我正在從數據庫加載數據,所以這就是它必須通過控制器的原因。
在_layout上我只放置了adminlte的<body>
,然后在我放置了呈現索引的@renderbody()
的頁面的主要區域。 索引包含Adminlte模板和大多數腳本的
有風格
<style type="text/css">
.dropdown {font-size:2em;}
.notifications-menu {color:red;}
.dropdown div, .notifications-menu div {font-weight:bold;}
</style>
並列出項目
<ul>
<li class="dropdown notifications-menu">
<!-- Menu toggle button -->
@Html.Action("Notifications", "Home")
</li>
</ul>
<ul>
<li class="dropdown notifications-menu">
<!-- Menu toggle button -->
<div>
@Html.Action("Notifications", "Home")
</div>
</li>
</ul>
我發現類選擇器.dropdown或.notifications-menu提供的樣式效果沒有區別,div元素的額外特異性也可以按預期工作。 您的樣式選擇器如何聲明?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.