数据注释/验证工作不适合局部视图 [英] Data Annotations / Validation not working for partial views

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

问题描述

我在运行时加载某些局部视图,根据用户的输入。

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()).

我想我做错了什么,但不知道是什么。任何意见大大AP preciated。

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

推荐答案

只包含JS文件即 jQuery的不显眼的js 文件还那么它做工精细,一些次此问题出现在局部视图中的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天全站免登陆