是否有可能获得标准的ASP.NET MVC不显眼的验证在果园CMS工作? [英] Is it possible to get standard ASP.NET MVC Unobtrusive Validation to work in Orchard CMS?

查看:97
本文介绍了是否有可能获得标准的ASP.NET MVC不显眼的验证在果园CMS工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个自定义模块与果园CMS集成,实现业务应用。虽然果园CMS是一个MVC应用程序,它似乎并不可能(或至少容易)做一切可以做的开箱即用与MVC的东西。

I'm trying to build a custom module to integrate with Orchard CMS to implement a business application. While Orchard CMS is an MVC application, it doesn't seem possible (or, at least easy) to do all the things that can be done "out of the box" with MVC.

我试图让不显眼的审定对我的看法工作,但似乎无法得到这个工作。

I'm trying to get unobtrusive validation to work on my view but can't seem to get this to work.

更新:按下面罗汉西方的建议,现在我已经得到了使用ResourceManifest类包含在页面的脚本和Script.Require调用

Update: As per Rohan West's advice below, I've now got the scripts included in the page using the ResourceManifest class and the Script.Require calls.

但是,验证实际的HTML元素属性不被产生,尽管有我的属性.NET属性我使用@ Html.EditorFor上哪个。

However, the validation attributes on the actual HTML elements are not being generated despite having the .NET attributes on my properties for which I'm using @Html.EditorFor on.

我已经设置在web.config文件中的appSettings如下:

I have set the appSettings in the web.config file as follows:

<appSettings>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>      

    <add key="webpages:Enabled" value="false" />
    <add key="log4net.Config" value="Config\log4net.config" />
</appSettings>

仍然没有喜悦!

更新2:按罗汉西的建议,修改OrchardStarter类注释掉以下行解决的问题:

Update 2: As per Rohan West's suggestion, modifying the OrchardStarter class to comment out the following lines "solves" the problem:

    ModelValidatorProviders.Providers.Clear();
    ModelValidatorProviders.Providers.Add(new LocalizedModelValidatorProvider());

有应该是,虽然处理这个更好的方法。

There should be a better way of handling this though.

推荐答案

您需要在资源清单为你的模块定义的脚本。

You need to define the script in the resource manifest for your module.

public class ResourceManifest : IResourceManifestProvider
{
    public void BuildManifests(ResourceManifestBuilder builder)
    {
        var manifest = builder.Add();

        manifest.DefineScript("jQueryValidation").SetUrl("jquery.validate.js", "jquery.validate.min.js").SetVersion("1.7").SetDependencies("jQuery");
        manifest.DefineScript("jQueryValidation_Unobtrusive").SetUrl("jquery.validate.unobtrusive.js", "jquery.validate.unobtrusive.min.js").SetDependencies("jQuery", "jQueryValidation");
    }
} 

,然后在你的页面

and then in your page

@{ 
    this.Script.Require("jQueryValidation_Unobtrusive").AtHead(); 
}

看一看下面的类

Orchard.Environment.OrchardStarter

在乌节1.4.2有一个线,删除所有ModelValidatorProviders

In Orchard 1.4.2 there is a line which removes all ModelValidatorProviders

ModelValidatorProviders.Providers.Clear();

这是从本集合的默认DataAnnotationsModelValidatorProvider。
你可以尝试将其添加到集合,

This is removing the default DataAnnotationsModelValidatorProvider from the collection. You could try adding it to the collection,

这篇关于是否有可能获得标准的ASP.NET MVC不显眼的验证在果园CMS工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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