Showing Different fields in EditorForModel vs. DisplayForModel modes in MVC2
- by CodeGrue
I have a viewmodel that has an int StateID field and a string StateName field like so:
public class DepartmentViewModel : BaseViewModel, IModelWithId
{
// only show in edit mode
public int StateId { get; set; }
// only show in display mode
public string StateName { get; set; }
}
I have a read only view that uses DisplayForModel and an update view that uses EditorForModel. I want the DisplayForModel view to show the StateName property, and the EditorForModel view use the StateID property (I am actually rendering a dropdownlist based on this).
I have not been able to figure out how to decorate my viewmodel properties to create this behavior.