2

我正在使用 MVC4/EF,我有四个级联下拉列表,我第一次就让它工作了。因此,当页面第一次呈现时,我可以选择第一个下拉列表并在第二个下拉列表中过滤结果,通过选择第二个 dropdowm,第三个 dropdwon 被过滤,第四个并基于第四个下拉列表填充编辑视图。但是,当我返回并更改第一个下拉列表中的选择时,它会过滤第二个下拉列表,但不会重置第三、第四个 dropdwon 列表和编辑部分视图。这是第一个 dropdwon 部分视图代码。

CampusUsercontrol.cshtml

@model RHMS.Models.RoomEditor
@using (Ajax.BeginForm("SelectCampus", "RoomEditor", new AjaxOptions { UpdateTargetId  = "Buildings" }))
{ 
@Html.DropDownListFor(
        m => m.SelectedCampusID,
        new SelectList(Model.Campuses,"CampusId", "Name"),
       string.Empty
    )
}

<script type="text/javascript">

$('#SelectedCampusID').change(function () {
    $(this).parents('form').submit();

 });
</script>

索引.cshtml

 @model RHMS.Models.RoomEditor
 @{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
 }
   <table cellpadding="0" cellspacing="4" border="0">
<tr>
    <td>Campus </td>
    <td> :</td>
    <td>@Html.Partial("CampusUserControl", Model)</td>
</tr>
<tr>
    <td>Building </td>
    <td> :</td>
    <td><div id="Buildings">@Html.Partial("BuildingUserControl", Model)</div></td>
</tr>
<tr>
    <td>Floor </td>
    <td> :</td>
    <td><div id="Floor">@Html.Partial("FloorsUserControl", Model)</div></td>
</tr>
 <tr>
    <td>Room </td>
    <td> :</td>
    <td><div id="Room">@Html.Partial("RoomUserControl", Model)</div></td>
</tr>
</table>
<div id="RoomInfo">
@Html.Partial("RoomInfoUserControl", Model)
</div>

请帮助我在更改第一个部分视图时如何刷新其他部分视图。

4

1 回答 1

1

Looks like this part of your javascript code is beeing executed only on the first load of the page

<script type="text/javascript">

$('#SelectedCampusID').change(function () {
    $(this).parents('form').submit();

 });
</script>

try wiring the change event for #SelectedCampusID using Jquery's on binding. You might also have to do the same for the other dropdowns.

于 2013-06-19T13:26:31.640 回答