Parsing model partial DisplayName to view model template?

You should be able to get display name for current model from model metadata, like this.

Up vote 0 down vote favorite share g+ share fb share tw.

If I have a Model with a partial file MetadataType(typeof(ClassAMetadata)) public partial class ClassA: IStructualObject { } public class ClassAMetadata { DisplayName("Var B:") public object VarB { get; set; } } And Var B is a DateTime! Then I have a ViewModel (ClassAViewwModel) for the controller using ClassA, in this ViewModel I ClassA and it also have a DateTimeViewModel of VarB, the reason for this is that in my application DateTime is shown as 3 fields Date, Hour and Minute. I then created a Template for my DateTimeViewModel.

See the code: @model ViewModels. DateTimeViewModel @Html. LabelFor(m => m) @Html.

TextBoxFor(m => m. Date, new { id = "participating_airborne_@ViewData_" + ViewData"cssname" + "_resource_date", @class="datepicker dato", maxlength="10"}) @Html. TextBoxFor(m => m.

Hour, new { id = "participating_airborne_" + ViewData"cssname" + "_resource_hours", @class = "time", maxlength = "2" }) : @Html. TextBoxFor(m => m. Minute, new { id = "participating_airborne_" + ViewData"cssname" + "_resource_minutes", @class = "time", maxlength = "2" }) @Html.

ValidationMessageFor(m => m. Date) @Html. ValidationMessageFor(m => m.

Hour) @Html. ValidationMessageFor(m => m. Minute) What I then want is to somehow get the DisplayName from my VarB to be shown when I do @Html.

LabelFor(m => m) on my DateTimeViewModel (Or something similar) so I need a way to read that Partial information, is this possible? C# asp.net .net asp.net-mvc-3 link|improve this question edited Nov 10 '11 at 7:54Prasanth1,751418 asked Nov 10 '11 at 7:27Mech0z397110 79% accept rate.

You should be able to get display name for current model from model metadata, like this: ViewData.ModelMetadata.GetDisplayName() EDIT: If you have view model: public class ClassA { DisplayName("Var B:") public DateTimeViewModel VarB { get; set; } } And then in ClassA view you render that property like: @Html. EditorFor(x => x. VarB) Then it should use your DateTimeViewModel template and be able to extract the display name from model metadata.

If I am in my View with the ClassAViewModel then if I do what you write I will get the displayname for ClassA, I cant seem to make it give me the Display for the properties in ClassAViewModel – Mech0z Nov 10 '11 at 9:48 I edited my post to include sample usage how it should work – Siim Nov 10 '11 at 10:12.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions