Can the properties of a model be accessed indirectly in a Razor view?

If Model. Columns is a list that would almost work. You would need to change it to this though.

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

So instead of: @Html. LabelFor(model => model. ColA) @Html.

LabelFor(model => model. ColB) @Html. LabelFor(model => model.

ColC) Is something like the following possible? @foreach (var col in Model. Columns) { @Html.

LabelFor(model => modelcol) } I should qualify that the model to be used will be an EF model: public class Record { Key, Display(Name="Column A") public string ColA { get; set; } Display(Name="Column B") public string ColB { get; set; } Display(Name="Column C") public string ColC { get; set; } } public class RecordDbContext : DbContext { public DbSet Records { get; set; } } How might I implement 'Columns' to show the display name for the property? Asp. Net-mvc-3 razor link|improve this question edited Jan 5 at 5:42 asked Jan 4 at 9:40brettski11.

If Model. Columns is a list that would almost work. You would need to change it to this though: @foreach (var col in Model.

Columns) { @Html. LabelFor(model => col) }.

Seems like your view model is not adapted to the requirements of your view (which is to loop through some values and display labels about them). You could use a collection in your view model instead of properties as it will allow you to loop: public IEnumerable Columns { get; set; } Then in your view instead of writing a loop you could use a display template: @model MyViewModel @Html. DisplayFor(x => x.

Columns) and then define the corresponding template which will automatically be rendered for each element of the Columns collection (~/Views/Shared/DisplayTemplates/SomeModel. Cshtml): @model SomeModel @Html. LabelFor(x => x.

SomeModelProperty).

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