我在asp.net mvc3应用程序中有客户端验证问题.
我的代码看起来
function loadEditCategoryDialog(categoryId) { $.ajax({ url : "/rovastamp3/Admin/CategoryEditDialog",data : "categoryId="+categoryId,success : function(data){ $("#popup_dialog").html(data); $("#popup_dialog").dialog({ modal: true,draggable: false,resizable: false,title: "Upravit kategorii",width: 600,height: 500,}); } }); }
控制器:
[HttpGet] public ActionResult CategoryEditDialog(int categoryId) { CategoryEditviewmodel categoryEditviewmodel = new CategoryEditviewmodel(); categoryEditviewmodel.Category = _postAuctionCategoryRepo.Query() .SingleOrDefault(x => x.Id == categoryId); return PartialView(categoryEditviewmodel); } [HttpPost] public ActionResult CreateNewCategory(CategoryEditviewmodel categoryEditviewmodel) { if (ModelState.IsValid) { return RedirectToAction("Index"); } return View("CategoryEditDialog",categoryEditviewmodel); }
最后我的部分看法:
@model Rovastamp.MVC3.viewmodels.AdminController.CategoryEditviewmodel <h2>Upravit kategorii @Model.Category.Name</h2> @{Html.EnableClientValidation();} @using (Html.BeginForm("CreateNewCategory","Admin")) { @Html.ValidationSummary(true) <fieldset> <legend>Objednávkový formulář</legend> <div class="editor-label"> @Html.LabelFor(model => model.Category.Name) </div> <div class="editor-field"> @Html.TextBoxFor(model => model.Category.Name) @Html.ValidationMessageFor(model => model.Category.Name) </div> <div class="editor-label"> @Html.LabelFor(model => model.Category.Position) </div> <div class="editor-field"> @Html.TextBoxFor(model => model.Category.Position) @Html.ValidationMessageFor(model => model.Category.Position) </div> <input type="submit" value="Upravit" class="submit_button" /> </fieldset> }
在我的web.config中,我打开了UnobtrusiveJavaScript和ClientValidatin应用程序设置.
如果我在jquery ui对话框上提交按钮,mvc在没有客户端验证的情况下完全刷新?
哪里有问题?
感谢任何帮助
编辑:
> jquery.unobtrusive-ajax.js
> jquery.validate.js
> jquery.validate.unobtrusive.js
编辑2
在我的exemaple我放:
jQuery.validator.unobtrusive.parse('#popup_dialog');
之前我调用jquery ui对话框和客户端验证工作完美.
解决方法
这是因为您正在将PartialView加载到已由jquery.validator.unobstrusive库解析的View中.您需要指示库重新解析页面以考虑您注入的PartialView验证属性.阅读我的
this blog post的这个话题,希望能回答你的问题.