I have problem with client validation in asp.net mvc3 application.
My code looks :
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,
});
}
});
}
Controller :
[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);
}
And finally my partial view :
@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>
}
In my web.config I turned on UnobtrusiveJavaScript and ClientValidatin app settings.
If I clik on submit button on jquery ui dialog, mvc does full refresh without client validation?
Where is the problem?
Thanks for any help
EDIT :
In my Layout page i include this scripts :
- jquery.unobtrusive-ajax.js
- jquery.validate.js
- jquery.validate.unobtrusive.js
EDIT 2
In my exemaple i put :
jQuery.validator.unobtrusive.parse('#popup_dialog');
before i call jquery ui dialog and client validation works perfectly.