views:

3642

answers:

3

Anyone got any idea on how to specify text when using Html.LabelFor(c=>c.MyField). It's just MyField might not be an appropriate name to display on screen, you may want "The Super Fantastic Field" instead, but there doesn't appear to be any overloads.

Any ideas?

A: 

I haven't checked out CP1 yet but I read over Scott's release of it and I seem to recall that the code was generated by T4. I suppose you could always mod that, but I would suspect that they will provide overloads in CP2.

Edit: The source is always available and thus you could just mod the method, change the T4 generator, and you'll be good to go. Also put in a ticket or request (somehow) for that mod so it gets worked into the next version.

Chance
Shame, I'm doing a work preview but it's not really viable as our field names are quite spurious compared to their description counterparts.
Kezzer
A: 

I haven't downloaded v2 yet, so I can't test, but I believe it works like DynamicData, in which case you'd do something like this on your model:

[Display(Name = "The Super Fantastic Field")]
public string MyField {get;set;}
Daniel
Display isn't available, and intellisense can't find it in any libs either.
Kezzer
Add a reference to System.ComponentModel.DataAnnotations.dll and add using System.ComponentModel.DataAnnotations.
Daniel
Rather, add reference to System.ComponentModel.DataAnnotations from the GAC (ie in the .NET tab of add references)
Daniel
I use DataAnnotations already, so the reference isn't the problem.
Kezzer
Ah, sorry - that's apparently Silverlight3/.NET 4.0: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute%28VS.100%29.aspx I think DisplayName is going to do what you want, as itsmecurtis suggests. Here's more on that: http://davidhayden.com/blog/dave/archive/2009/08/19/DisplayNameAttributeInMVC.aspx
Daniel
+25  A: 

You use the DisplayName attribute (System.ComponentModel.DisplayNameAttribute):

[DisplayName("My Field")]
public string MyField { get; set; }
itsmecurtis
I'll test this tomorrow.
Kezzer
You're the winner. You've got to have `using System.ComponentModel;` though.
Kezzer
I have my code generator spit these out automatically, inserting spaces between Pascal-cased words. Works like a charm!
GalacticCowboy