views:

49

answers:

1

I've found information about Editor and Detail templates based on object name (i.e. DateTime, MyCustomObject) for use with MVC system. I am just wondering if it was possible for creating templates for use when creating the items in a similar fashion, where the form used for Creating the items is going to be different than the Editing Screen.

+1  A: 

Yes you can tell MVC to distinguish between templates a few different ways.

You can tell the view what template to use.

<%= Html.EditorFor(model => model.MyCustomObject, "MyCustomObjectCreate") %>

vs

<%= Html.EditorFor(model => model.MyCustomObject, "MyCustomObjectEdit") %>

Or if you are using view models you can use Data Annotations to tell it what template to use right in the model.

So your Edit view model would look like this:

public class MyCustomObjectEditViewModel
{
    [UIHint("MyCustomObjectEdit")]
    MyCustomObject CustomObject { get; set; }
}

and your Create view model would look like this:

public class MyCustomObjectCreateViewModel
{
    [UIHint("MyCustomObjectCreate")]
    MyCustomObject CustomObject { get; set; }
}
Steve Hook