ASP.NET MVC EnableClientValidation
Does this <% Html.EnableClientValidation(); %>
really enable client validation that validation without page refresh or not?
The thing is that it is doing a page refresh while returning formviewmodal ,it is working fine when using modal ? So how will i make it work using formviewmodal
here is the code of the controller returning FormViewModel
public class OrganizationGroupFormViewModel
{
public OrganizationGroup OrganizationGroups { get; set; }
public OrganizationGroupFormViewModel() { }
public OrganizationGroupFormViewModel(OrganizationGroup OrganizationG)
{
OrganizationGroups = Organizatio开发者_如何学JAVAnG;
}
}
public class OrganizationGroupsController : Controller
{
public ActionResult Create()
{
OrganizationGroup OrgGroup = new OrganizationGroup
{
int_CreatedBy = Authorization.UserID,
dtm_CreatedDate = DateTime.Now
};
return View(new OrganizationGroupFormViewModel(OrgGroup));
}
[HttpPost]
public ActionResult Create(OrganizationGroup OrgGroup)
{
try
{
if (ModelState.IsValid)
{
OrgGroup.int_CreatedBy = Authorization.UserID;
OrgGroup.dtm_CreatedDate = DateTime.Now;
OrganizationGroupRepository.Add(OrgGroup);
OrganizationGroupRepository.Save();
return View(new OrganizationGroupFormViewModel(OrgGroup));
}
else
return View(new OrganizationGroupFormViewModel(OrgGroup));
}
catch
{
return View(new OrganizationGroupFormViewModel(OrgGroup));
}
}
Yes, this helper method adds the appropriate javascript to the page in order to enable client validation. You will need to include the proper js scripts based on the framework you are using. Take a look at this blog post.
精彩评论