我使用脚手架选项创建了一个部分视图(MVC4),用于创建操作,我只是尝试将其加载到jquery对话框中,我能够在加载时加载部分view.but,我丢失了MVC 4为我生成的所有验证。
能否将部分视图(脚手架)加载到jquery对话框中?
这是我用来弹出的代码
$(function () {
$("#CreateDialog").dialog({
autoOpen: false,
buttons: {
"Create": function () {
$(this).dialog("close");
}
},
dialogClass: "no-title",
hide: {
effect: "scale",
easing: "easeInBack"
},
show: {
effect: "scale",
easing: "easeOutBack"
}
});
});
function openModalPopUp() {
$.ajax({
type: 'GET',
url: '/Expense/CreatePartial',
cache: false,
success: function (result) {
$('#CreateDialog').html(result);
}
});
$("#CreateDialog").dialog("open");}
我的模型(样本):
@model EFMvcWebRole.Models.ExpenseEntity
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>ExpenseEntity</legend>
<div class="editor-label">
@Html.LabelFor(model => model.ECValue)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ECValue)
@Html.ValidationMessageFor(model => model.ECValue)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Category)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Category)
@Html.ValidationMessageFor(model => model.Category)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.TotalSalary)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.TotalSalary)
@Html.ValidationMessageFor(model => model.TotalSalary)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Remaining)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Remaining)
@Html.ValidationMessageFor(model => model.Remaining)
</div>
</fieldset>发布于 2014-09-14 02:38:42
只需在部分视图中包含JS文件--即Jquery Unobtrusive js文件--也就可以很好地工作,有时这个问题出现在asp.net mvc中的部分视图中(因为表单是动态添加到DOM中的)。
只需将这个js文件包含在您的部分视图中就可以了:
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>$.validator.unobtrusive.parse($("form"));https://stackoverflow.com/questions/25826657
复制相似问题