在System.Web.Webpages.Html HtmlHelper类VS System.Web.Mvc命名空间 [英] HtmlHelper class in System.Web.Webpages.Html vs System.Web.Mvc namespaces

查看:257
本文介绍了在System.Web.Webpages.Html HtmlHelper类VS System.Web.Mvc命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET MVC3我想设置的CSS类的验证错误的helper方法集。 (不这个问题,公认的答案,只是增加了类,我想完全覆盖它。)在看MVC3源,我发现对HtmlHelper类的 ValidationInputCssClassName 属性。它是可设置的,如果将​​其设置存储在存储提供商的值。该属性返回get方法[提供商值] ?? [默认的类名。

In ASP.NET MVC3 I'm trying to set the css class that the validation error helper method sets. (Not this question, the accepted answer just ADDS the class, I want to override it completely.) In looking at the MVC3 source I've found the ValidationInputCssClassName property on the HtmlHelper class. It is settable and it stores the value in a storage provider if set. The get method for the property returns [the provider value] ?? [the default class name].

现在,如果你只需要输入 HtmlHelper.ValidationInputCssClassName (<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper.validationinputcssclassname.aspx\">MSDN进入)在控制器code,你会看到,它是一个静态只读字段。这样做的原因是,有两个班的HtmlHelper,一个是在 System.Web.Mvc 命名空间,另一个是在系统。 Web.Webpages.Html 命名空间。酒店 System.Web.Webpages.Html.HtmlHelper.ValidationInputCssClassName (<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.webpages.html.htmlhelper.validationinputcssclassname%28v=vs.99%29.aspx\">MSDN进入)可以设定,但它似乎没有任何效果产生code不管我在哪里设置。

Now if you just type in HtmlHelper.ValidationInputCssClassName (MSDN entry) in your controller code you'll see that it is a static readonly field. The reason for this is that there are two HtmlHelper classes, one is in the System.Web.Mvc namespace, and the other is in the System.Web.Webpages.Html namespace. The property System.Web.Webpages.Html.HtmlHelper.ValidationInputCssClassName (MSDN entry) can be set, but it doesn't seem to have any effect the generated code no matter where I set it.

我在想什么?而这些类之间的区别是什么呢?

What am I missing? And what is the difference between these classes?

推荐答案

我不是正面的,但我觉得 System.Web.WebPages.Html 是使用ASP。净WebForms的剃刀。

I'm not positive but I think System.Web.WebPages.Html is for using ASP.net WebForms with Razor.

由于 ValidationInputCssClassName 等都是只读字段,我想你会来解决这个问题的唯一方法是通过创建自己的HtmlHelper扩展方法,所以你可以自定义这一行为。

Since ValidationInputCssClassName, etc. are all readonly fields, I think the only way you are going to get around this is by creating your own HtmlHelper extension methods so you can customize this behavior.

MSDN :

该System.Web.WebPages命名空间包含所使用的核心类
  渲染和执行使用ASP.NET网页制作的网页
  用剃刀语法。

The System.Web.WebPages namespace contains core classes that are used to render and execute pages that are built using ASP.NET Web Pages with the Razor syntax.

这篇关于在System.Web.Webpages.Html HtmlHelper类VS System.Web.Mvc命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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