开发者

Some Confusion / Query Related to MVC2

开发者 https://www.devze.com 2023-03-14 14:43 出处:网络
I have just started using MVC 2 , I have got a couple of queries , may be 开发者_如何学运维you guys can help me to clear my confusion.

I have just started using MVC 2 , I have got a couple of queries , may be 开发者_如何学运维you guys can help me to clear my confusion.

Why mvc doesnt allows to inherit multiple models on a view page. For instance if i inherited account model in my view , why i cant excess the associated entity properties with the account model in that view, We are only allowed to use the properties of that model like <%: Model.FirstName :%> Where First name is the property of account model. Why we cannot use <%:Model.account.aspnet_users.vehicle.make %> Where aspnet_users is associated with account through a foreign key vice versa. MVC 2 only allows <%:Model.account.aspnet_users.vehicle %> Therfore I cant use the associated property of vehicle which in this case is vehicle.make. I was thinking of doing something like <%: Html.TextboxFor(model => model.account.aspnet_users.vehicle.make %>.


ASP.NET MVC doesn't restrict navigation to related properties. If you cannot access the property it means either:

  • The relation is not loaded (it is null) and lazy loading is turned off / context is disposed
  • The relation is actually a collection an you must use Linq to navigate in the collection
0

精彩评论

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