Solved

MVC Label CSS question

Posted on 2013-01-31
2
478 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 74

Accepted Solution

by:
käµfm³d   👽 earned 100 total points
Comment Utility
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
Comment Utility
thanks again Kaufmed.  Huge help
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now