Showing Different fields in EditorForModel vs. DisplayForModel modes in MVC2

Posted by CodeGrue on Stack Overflow See other posts from Stack Overflow or by CodeGrue
Published on 2010-06-02T15:14:19Z Indexed on 2010/06/02 16:53 UTC
Read the original article Hit count: 605

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about editorformodel