惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
D
Docker
B
Blog
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
G
Google Developers Blog
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42

博客园 - hzwang

Administering your Windows Internal Database (MICROSOFT##SSEE) instance(转) VS 2008如何连接TFS 2010 learning F#(1):编程环境 learning F#: 开篇 Tip for using Fiddler on localhost I will write at least one blog every week 使用位逻辑运算来实现位向量 对象判等 sql bcp Utility工具使用 C# 3.0 —— 扩展方法 读代码随笔(一):using语句的使用 visitor(访问者)模式 - hzwang - 博客园 抽象类与接口(转) 在 C# 中实现 Singleton (转) 设置VSS2005使支持通过Internet访问 VSS使用手册 ASP.NET Forms 身份验证控制流 Cookie使用总结 不断努力,不断学习
(转载)ASP.NET MVC – Add CSS class Attribute
hzwang · 2010-03-25 · via 博客园 - hzwang

If you are a web developer, you probably are used to using the standard “class” attribute in your HTML. If you typically use ASP.NET Web Forms, you are probably used to using the CssClass property on your web server controls. But, if you are new to ASP.NET MVC like me, you may be surprised to learn that the HtmlHelper extension methods do not explicitly provide a parameter for your styling needs.  Instead, if you are using C#, you need to use the object initializer syntax introduced in C# 3.0. To cut to the chase, adding a “class” attribute to an input element generated by a HtmlHelper extension method looks like this:

<%= Html.TextBox(”myTextBox”, null, new{@class = “required”}) %>

Please notice how @class is in bold. The reason for this is because the @ prefix is necessary in this specific case because class is a keyword in C#. If you omit the @ prefix, you will receive a compile time error that says:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1513: } expected

The reasons for wanting to add CSS class information to your HTML elements are numerous. You may simply want to stylize your HTML elements. Or, you may want to prepare your elements to work with a JavaScript framework like JQuery. Regardless of the reason, if you would like to learn more about ASP.MVC, I recommend ASP.NET MVC in Action (or you could just skip MVC and learn Silverlight :) ). As someone that has traditionally written applications using the ASP.NET Web Forms approach I hope to write more about the challenges I come across. What challenges are you experiencing in ASP.NET MVC that you were comfortable overcoming with the ASP.NET Web Forms style?

原文链接:http://blog.ecofic.com/?p=311