我认为这是我的HTML / CSS代码的问题,因为这些是我明显的弱点。我有一个局部视图,我只想在有人从下拉框中选择一个选项时显示。正在加载这个局部视图(_ChampionStats),我可以在那里放置一个断点并看到它被击中,但数据从未显示过。有什么建议吗?
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
答案 0 :(得分:0)
你需要使用
@Html.RenderPartial
答案 1 :(得分:0)
404意味着路径http://localhost:49219/jquery.js
不存在。 jquery的默认位置是scripts文件夹,包含版本http://localhost:49219/scripts/jquery-1.8.3.js
。您可以使用浏览器f12中的工具来检查文件是否被找到,即Chrome中的网络或者fiddler会为您提供更多信息
添