我相信這是我的HTML/CSS代碼的問題,因爲這些都是我明確的弱點。我有一個局部視圖,我只想在有人從下拉框中選擇一個選項時顯示。這個局部視圖(_ChampionStats)正在被加載,我可以在那裏放置一箇中斷點並且看到它被擊中,但是數據從不顯示。有什麼建議麼?部分視圖數據未顯示MVC 4
Index.cshtml:
@using LoLBuild.Models
@model ChampionViewModel
<script type="text/javascript" src="~/jquery.js"></script>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Choose Your Champion</h2>
<div class="inputblock" style="clear: both;width:100%;">
@Html.LabelFor(model => model)
@Html.DropDownList("ChampionList", (IEnumerable<SelectListItem>)ViewBag.ChampionSelectList, new { @onchange="location = Index/this.value;" })
</div>
<div id="ChampionStats">
@if (ViewBag.SelectedChampion > 0)
{
@Html.Partial("_ChampionStats", Model);
}
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#ChampionList").change(function() {
var strSelected = "";
$("#ChampionList option:selected").each(function() {
strSelected += $(this)[0].value;
});
var url = "/Champion/Index/" + strSelected;
$.post(url, function(data) {
// do something if necessary
});
});
});
</script>
局部視圖(_ChampionStats.cshtml):
@using LoLBuild.Models
@model ChampionViewModel
@{
ViewBag.Title = "ChampionStats";
}
<h3>Partial Rendered Successfully</h3>
@Html.TextBox("Health:", Model.BeginHealth, new {style = "width: 100px;"})
編輯:我注意到,有一個在控制檯的錯誤,但我我不確定這意味着什麼。這是錯誤:
GET http://localhost:49219/jquery.js 404 (Not Found) localhost:8
Uncaught ReferenceError: Index is not defined localhost:36
onchange
我試圖這樣做,但它沒有得到任何結果。我仍然能夠在局部視圖中放置一個斷點,並且看到它實際上被調用並且可以找到視圖,但屏幕上沒有任何東西出現。下面是我對索引視圖進行的代碼更改: