Data Annotations / Validation not working for partial views

后端 未结 2 440
时光取名叫无心
时光取名叫无心 2021-01-07 01:59

I have some partial views loaded at runtime, based on user input.

$(\"#Categories\").change(function () {
        $.ajax({
            url: \"/Product/Crea         


        
相关标签:
2条回答
  • 2021-01-07 02:05

    Just Include JS files i.e Jquery Unobtrusive js file in your Partial View also then it work fine ,some times this problem comes in partial view in asp.net mvc.

    Just include this js file in your Partial View also :

    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    

    ------------------OR try this in Partial View--------------------------

    $.validator.unobtrusive.parse($("form"));
    
    0 讨论(0)
  • 2021-01-07 02:17

    try this if you are appending form in html

    var formid = $("#frmAddProduct");
    formid.unbind();
    formid.data("validator", null);
    $.validator.unobtrusive.parse($("#frmAddProduct"));
    

    OR use in partial view on document ready

    $.validator.unobtrusive.parse($("form"));
    
    0 讨论(0)
提交回复
热议问题