Solved

MVC Label CSS question

Posted on 2013-01-31
2
500 Views
Last Modified: 2013-01-31
Hello all,

What is the best way to handle dealing with css properties within MVC.  For example, I have a design template that has labels etc. that have a class defined such as this:

<label for="testlabel" class="control-label">Customer ID</label>

<input type="text" id="testtb"></input>

So the input I think I can just use a EditorFor or TextBoxFor.   What should I do with the labels?  Not sure if just leave it as they are or if true MVC I should be using something different.

Thanks
0
Comment
Question by:sbornstein2
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 100 total points
ID: 38841438
The EditorFor, TextBoxFor, and any other *For methods are just helper methods. Don't get too caught up in thinking that they are the embodiment of MVC. MVC is the architectural style regarding how your app is put together (the mdoels, views, and controllers). The helpers just make placing the HTML controls that would associated with various parts of your model a bit easier.

You can create a new anonymous object that has the attributes you would like to add to the label.

e.g.

@Html.LabelFor(modelItem => modelItem.Message, "Customer ID", new { @class = "control-label" })

Open in new window


...this is the new { @class = "control-label" } part in the above example. In this particular case, the "@" on "@class" is required since the keyword "class" is a reserved word in C#.
0
 

Author Closing Comment

by:sbornstein2
ID: 38841443
thanks again Kaufmed.  Huge help
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Initial get page response times and IIS8 15 51
Reading the Web.Config using IIS 7.5? 4 36
tutorial for ebay api 3 35
.NET 2008 VB and C# 6 28
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question