Can I access the parent view of the Model from a child partial view?

Can I access the parent view of the Model from a child partial view? I get conflicting information when I look at it.

If so, can someone point me to an example?

And if so, will this help make the child model object a property of the parent model?

+5
source share
1 answer

Not. If you say that you strongly bind views to ViewModels, you can only access the model that you pass to your partial view. But if you want something to be available in a partial view or in any other view, you can use the ViewData dictionary.

Another thing that you can always do and should do is to make a model of your look in such a way that it matches your parental view, as well as all your children's ideas. Therefore, to answer your last question, yes, you can create a child model of object - a property of your parent model.

Another point is to make sure that your domain model is separate from the View model that you intend to associate with the views, and do not make any changes to the user interface in your domain model just for the sake of viewing.

+6
source

Source: https://habr.com/ru/post/1206229/


All Articles