0

How on earth do you add labels in MVC2? Intellisence says that there is an overload for label that takes 2 strings. I am getting an error telling me there is no such overload. And there doesn't appear to be any documentation anywhere telling how to do it? How do you do it in mvc2?

Update: Added an example of how I am trying to add a label

    %><%=Html.Label(labelId, labelText)%><%

I was just reading that I may have to write an extension method of some sort. Do you know how to do that?

SoftwareSavant
  • 9,467
  • 27
  • 121
  • 195

1 Answers1

2

you have following options: Static label to render text

<%= Html.Label("string to be displayed") %>

Label for model

<%= Html.LabelFor(model=>model.YourObject) %>

Where entity (class that represents the model is defined

public class Foo{
[DisplayName("Team")]
public string YourObject{get;set;}
}

this was basic usage

documentation is here for all of Html.Label labelfor and labelformodel http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k%28SYSTEM.WEB.MVC.HTML.LABELEXTENSIONS.LABEL%29&rd=true

Update:

definition for Html.Label("string"):

MvcHtmlString AdministratorMenuLink(this HtmlHelper helper, string text){}

Where this HtmlHelper is internal which you never use unless you test. It is intergrated because it is extending this function.

In this case you ignore it and follow up only with the text.

cpoDesign
  • 8,953
  • 13
  • 62
  • 106
  • So why does my intellisense tell me that I have a 2 string option? I literaly want to have a label for some of the Id's that I have? Will I have to write out – SoftwareSavant Aug 25 '11 at 11:04