views:

406

answers:

1

I know this works for single properties as per Scott Guthrie's blog to auto-magically use a partial view to render a partial model passed to it (UI Helper like in dynamic data):

[UIHint("StateDropDown")]
public string State { get; set;}

But how do you annotate an entire class to use an UI helper like this:

[UIHint("Address")]
public class Address {
    public string addr1 { get; set; } 
    public string addr2 { get; set; } 
    public string city { get; set; }
    [UIHint("StateDropDown")]
    public string state { get; set; } 
    public string zip { get; set; } 
}

(Except [UIHint("Address")] doesn't seem to work on classes. I see in his examples, he has "Customer.aspx" in the Shared->EditorTemplates folder, so I assume this is possible.

+3  A: 

Make a template with the name of the class, and it just works.

Brad Wilson
Great! I saw a Html.EditorForModel("nameOfViewTemplate") too. I suppose that the view template can decide what fields to show, and that MVC will populate the fields it can (if the view is missing model fields).Since we wouldn't want more than one BeginForm(), I suppose that if you have multiple entities in the same form, you wouldn't put the BeginForm in the view templates (partial pages)?
Dr. Zim
It would be really nice if we could do this:Html.EditorForModel("Address", Model.appEmployee.empAddress )
Dr. Zim
Html.EditorFor(model => model.appEmployee.empAddress, "Address")
Brad Wilson
Try out this question http://stackoverflow.com/questions/2069658/asp-net-mvc-ui-template-how-to-mix-an-ilist-model-property-with-editorfor-m
Dr. Zim