我相信这是我的 HTML / CSS 代码的问题,因为这些是我明显的弱点。我有一个部分视图,我只想在有人从下拉框中选择一个选项时显示。这个局部视图 (_ChampionStats) 正在加载,我可以在其中放置一个断点并看到它被击中,但数据从未显示。有什么建议么?
索引.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