In my view I want to be able to render out the ID of a model property independent of an associated control markup.
So for example, if my model was:
public class Author {
public string Title { get; set; }
public Address Address { get; set; }
}
In my view I would preferably like to be able to use an extension of HtmlHelper
to render out the Title
property's ID using a lambda. Something like:
@Html.GetClientIdFor(x => x.Title)
And this would output "Title".
In the case of nested objects, I would like:
@Html.GetClientIdFor(x => x.Address.PostCode)
to output "Address_PostCode".
I'm sure I can access the data from the ViewData.TemplateInfo
object but from there I'm a little stuck.
Any ideas? I am using MVC4 but I would like a solution that worked for MVC3 too.