数据注释/验证不适用于部分视图 [英] Data Annotations / Validation not working for partial views

查看:23
本文介绍了数据注释/验证不适用于部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行时根据用户输入加载了一些局部视图.

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

$("#Categories").change(function () {
        $.ajax({
            url: "/Product/Create" + $("#Categories option:selected").text().replace(/s+/, ""),
            type: "Get"
        }).done(function (partialViewResult) {
            $("#partialDiv").html(partialViewResult);
        });
    });

在视图模型中使用的 POCO 用数据注释修饰,但它们不会被触发.

The POCO's that are used in the view model are decorated with data annotations, but they are not triggered.

每个局部视图都包含一个表单(Html.BeginForm()).

The partial views each contain a form (Html.BeginForm()).

我想我做错了什么,但不确定是什么.非常感谢任何建议.

I guess I'm doing something wrong, but not sure what. Any advice greatly appreciated.

推荐答案

Just Include JS files ie Jquery Unobtrusive js file in your Partial View 也可以正常工作,有时这个问题是部分的在 asp.net mvc 中查看.

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.

只需将此 js 文件也包含在您的部分视图中:

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"));

这篇关于数据注释/验证不适用于部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆