本文介绍了ASP.NET MVC3 C#中的html助手的html属性是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你在MVC中使用HtmlHelpers时,你可以指定一组字典对象的html属性。

我在网上阅读了大量关于创建HtmlHelpers的资料,但我已经将注意力集中在jQuery和其他ASP.NET资源上,以便我必须尽快开发应用程序没有时间照顾Html Helpers定制。



我知道MVC3已经有一些属性可以像@class一样使用,但是在微软网站上没有关于htmlattributes的信息。你可以告诉我哪些属性可用,以及如何指定min C#?

我主要对禁用感兴趣,禁用特定控件,并且 id,来改变控件的id,因为默认的HtmlHelpers使用id和name的相同值。我需要它与jQuery一起使用它们。



预先感谢

Francesco

$ b $这些都是简单的HTML属性,所以你可以使用你正在使用的DOCTYPE中可用的任何属性。 ASP.NET MVC帮助器只需要这些属性并将它们发布到生成的HTML页面中。因此,如果您需要文档,请查看。



关于包含破折号的HTML5 data - * 属性只有一点点评论。因为破折号不能用作.NET中的变量名称,所以可以使用下划线将其转换为短划线。例子:

  @ Html.TextBoxFor(x => x.Foo,new {data_id =bar})

将会呈现为:

 < input type =textname =Fooid =Foovalue =some valuedata-id =bar/> 


when you use HtmlHelpers in MVC, you can specify a set of html attributes a a dictionary objects.

I read online a lot of material about creating HtmlHelpers but I am already focusing on jQuery and other ASP.NET stuff for an application that I have to develop ASAP and I do not have time to take care of Html Helpers customization as well.

I know that there are some attributes made already available by MVC3 like @class, but in the Microsoft website there is no information about the htmlattributes. May you please tell me which attributes are available and how I can specify themin C#?

I am mostly interested in the "disable",to disable a specific control, and "id", to change the id of a control, because the HtmlHelpers for default use the same value for id and name. I need it to use them with jQuery.

Thanks in advance

Francesco

解决方案

Those are simple HTML attributes, so you could use any attribute available in the DOCTYPE you are using. ASP.NET MVC helpers simply take those attributes and emit them in the resulting HTML page. So if you need a documentation take a look at the HTML specification.

There is just a little remark about HTML5 data-* attributes which contain dashes. Because dashes cannot be used as variable names in .NET you could use underscore which will be converted to a dash. Example:

@Html.TextBoxFor(x => x.Foo, new { data_id = "bar" })

which will be rendered as:

<input type="text" name="Foo" id="Foo" value="some value" data-id="bar" />

这篇关于ASP.NET MVC3 C#中的html助手的html属性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 14:00