【发布时间】:2013-07-29 12:09:20
【问题描述】:
我有这种情况:在选择任何国家后重新加载“州”div 内容的国家下拉列表。
@Html.DropDownListFor(m => m.SelectedCountry,
new SelectList(Model.Countries, "CountryId", "CountryName", Model.SelectedCountry))
<div id="states">
@Html.Partial("Partial/States", Model)
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#SelectedCountry').change(function() {
if ($(this).val() !== "-1") {
$.get('@Url.Action("LoadStates", "Controller")',
$('#form').serialize(), function(result) {
$('#states').html(result);
});
}
}
});
</script>
好的,它工作得很好。我的问题是当我重新加载这个 PartialView 时,内容丢失了它的 css 样式,我在 JS 引用中找不到它。我有这个功能可以根据选定的下拉值启用按钮。
<script type="text/javascript">
function canEnableButton() {
//...
}
$('#SelectedCountry, #SelectedState').change(function() {
canEnableButton();
}
</script>
change() jQuery 函数工作的第一个加载页面。当我重新加载时,此功能停止工作并且 CSS 样式消失。
有人知道可以是什么吗?谢谢!
【问题讨论】:
标签: jquery asp.net-mvc partial-views