简体   繁体   中英

Workaround to enable form validation on views dynamically loaded by ajax on Asp.Net Mvc3

That's a very common bug that happens to people who load a partial view via ajax and that view has a model with DataAnnotation validators. When u load the View the validation stop working.

How to fix that?

$.get("url", function()
{
    $.validator.unobtrusive.parse("#form-id");
});

@Mahmoud Moravej

I don't know if this is part of unobtrusive or not, but you can use

        $("form").validate({
            rules: {
                textbox1Id: "required",
                textbox2Id: "required"
            },
            messages: {
                textbox1Id: "*",
                textbox2Id: "omg you missed textbox2!"
            }
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM