0

我相信这是我的 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
4

2 回答 2

0

你需要使用

@Html.RenderPartial

http://msdn.microsoft.com/en-us/library/system.web.mvc.html.renderpartialextensions.renderpartial(v=vs.108).aspx

于 2013-03-26T10:12:52.800 回答
0

404 表示该路径http://localhost:49219/jquery.js不存在。jquery 的默认位置是脚本文件夹,并且包含版本 ie http://localhost:49219/scripts/jquery-1.8.3.js。您可以使用浏览器的 f12 中的工具来检查是否找到了文件,即 chrome 中的网络,或者 fiddler 会为您提供更多信息 Tim

于 2013-03-27T07:13:44.097 回答