Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

How can i add CSS class in aspx view of MVC.

Please convert the following razor view to aspx equivalent.

HTML
@Html.TextBoxFor(m => m.Code, new { @class = "marb15_I",@Title="Enter Code" })
Posted

1 solution

Your @HTML.TextBoxFor is correct. It is calling the CSS class marb15_I. In your _Layout.cshtml you should probably add a reference to your CSS document.
Two ways to do it:
or using razor @Styles.Render("~/CSS/mycss")

Converting Razor to web forms you'd get:
<asp:textbox id="txtEnter" cssclass="" marb15_i=" ToolTip=" enter="" code=" runat=" server="></asp:textbox></xml>" xmlns:asp="#unknown">
 
Share this answer
 
Comments
Prasad Avunoori 20-Mar-15 0:03am    
Hi,

Thanks for the quick response.
But, i need this in html helper some what below.
<%: Html.TextBoxFor(m => m.Code, new { @class = "marb15_I",@Title="Enter Code" })%>
jgakenhe 20-Mar-15 0:10am    
That is in correct format. It will be rendered in HTML as: <input id="Code" name="Code" type="text" class="marb15_1" />

If the problem is that your CSS is not being called, add a reference to it, such as above or inline CSS. http://www.w3schools.com/css/css_howto.asp
Prasad Avunoori 20-Mar-15 0:12am    
That didn't work for @Class not recognized by aspx view engine.
jgakenhe 20-Mar-15 0:18am    
What is the error? Are you getting a server error or is your CSS just not being displayed?
This is a workable example and is close to what you have:
@Html.TextBoxFor(m => Model.LastName, new { @class = "len25", maxlength = 25 })

Prasad Avunoori 20-Mar-15 0:27am    
I didn't get any error. But, when i see the source of the html other class is render as class="text-box single-line"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900