开发者

View for class/subclass objects

Step 2 in my quest for today is creating ASP.NET MVC 3 with Razor views that are able to handle class-subclass objects. So i want a form/page that can handle Person -> Woman or Person -> Man based on the selection of a DropDownList (Man/Woman).

The stuff is stored in the database using EF 4.1 Code First. Which works fine. Cause when I store a Woman, and I retrieve with context.Person.Where(p => p.Id == 1) it gets me a Woman object.

The problem I have is that I don't know what to use as a Model in the view.Person would be the m开发者_如何学Goost obvious, but then how would I be able to show/access/store the properties for Woman/Man. And in case of a create, the type is not known before hand (server side). The user can select either a Woman/Man, and expects to fill out the specific properties of a Woman or Man.

See this question for the model.


One way would be to create a separate partial view for Man and Woman, then load both views into divs on your page. Then use jquery to Hide/Show the divs after the drop down list selection changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜