2

I've found following code which creates custom Object template

@foreach (var prop in ViewData.ModelMetadata.Properties
.Where(pm => pm.ShowForEdit
&& !ViewData.TemplateInfo.Visited(pm))) {
    <div class="editor-field-container">
    @if (!String.IsNullOrEmpty(
       Html.Label(prop.PropertyName).ToHtmlString())) {
           <div class="editor-label">
              @Html.Label(prop.PropertyName): 
           </div>
     }
     <div class="editor-field">
        @Html.Editor(prop.PropertyName)
        @Html.ValidationMessage(prop.PropertyName, "*")
     </div>
<div class="cleaner"></div>
</div>
} 

Since this example loops through all the ModelMetadata.Propertiesthat should be shown for editing and have not been shown before, displaying the label, editor template, and validation message for each property in a set of divtags.

My question is: how can I set this ShowForEdit attribute. I tried with attribute inside my viewmodel as

using System.ComponentModel.DataAnnotations

[ShowForEdit]
public string Name {get; set;}

but this [ShowForEdit] is not set, obviously I'm missing something major here. Can someone explain me how to set property as ShownForEdit inside viewmodel?

update: and where this custom Object template should be saved (inside mvc4 app).

user1765862
  • 13,635
  • 28
  • 115
  • 220
  • 1
    you can look at that, maybe : http://stackoverflow.com/questions/5583464/how-to-exclude-a-field-from-html-editformodel-but-have-it-show-using-html-dis – Raphaël Althaus Mar 10 '14 at 19:48
  • I successfully implemented this solution http://stackoverflow.com/questions/2959041/showing-different-fields-in-editorformodel-vs-displayformodel-modes-in-mvc2 – Korayem Jul 04 '16 at 05:12

0 Answers0