开发者

How to make client side validation when loading Partial View in my page using jquery in Mvc2

I am returning partial view

public virtual PartialViewResult Create()
{
    return PartialView("Create");
}

and loading the view in my page when clicking create button with jquery

function createVendor() {
    jQuery.ajax({
        type: 'GET',
        url: 'Vendor/create',
        success: function (result) {
            $("#popup").html(result).fadeOut('slow').fadeIn('slow');
        }
    });
}

in my class I am using DataAnnotations for validation, making reference for js files and add adding

<% Html.EnableClientValidation(); %>

before begin form.

the problem is that when I cl开发者_StackOverflow社区ick save the first time with wrong data the validation not working but it is working the second time I click save.


Dear all I found the answer here thanks for you :

http://weblogs.asp.net/imranbaloch/archive/2010/07/11/asp-net-mvc-client-side-validation-with-dynamic-contents.aspx


My understanding of the EnableClientValidation() is that it examines the model and injects html wherever it needs to go. So you may need to call EnableClientValidation() again in your partial view you return.


This blogpost is a great resource if you're using the jQuery validation plugin. I know the question isn't asking about the plugin specifically but seeing as I arrived here while searching for help with it, I thought this might help someone else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜