# \[view models / page structuring series\] DotVVM Context null when instantiating MarkupControl view model at PostBack in command handler

**URL:** <https://forum.dotvvm.com/t/view-models-page-structuring-series-dotvvm-context-null-when-instantiating-markupcontrol-view-model-at-postback-in-command-handler/148>\
**Category:** Discussion in English\
**Created:** [February 19, 2024, 11:25am UTC](https://forum.dotvvm.com/t/view-models-page-structuring-series-dotvvm-context-null-when-instantiating-markupcontrol-view-model-at-postback-in-command-handler/148 "2024-02-19T11:25:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [February 19, 2024, 11:25am UTC](https://forum.dotvvm.com/t/view-models-page-structuring-series-dotvvm-context-null-when-instantiating-markupcontrol-view-model-at-postback-in-command-handler/148/1 "2024-02-19T11:25:57Z")

</div>

Well, for reasons of not complicating things further and make view model for the ModalDialog that is inside a MarkupControl, I’ve decided to work directly with the MarkupControl view model… nullifying it when needed (see [Simple validation crashing on just one property (+other validation issues)](https://forum.dotvvm.com/t/simple-validation-crashing-on-just-one-property-other-validation-issues/140) on discussion about good practices when doing data validations with nested page sections; also this issue is a follow up of switching to nullifying the view models of the sections).

How I open the popup (popup means a MarkupControl containing a ModalDialog control and this arrangement has to stay like this otherwise again other complications and more code 🫣):  
 ![image](https://forum.dotvvm.com/uploads/default/original/1X/c5e0f609a94c6b39965f87787e3e6f9dde4dd0b6.png)

When I try to open the popup, it crashes here, inside OperationInstance, with Context being null:  
 ![image](https://forum.dotvvm.com/uploads/default/original/1X/8ecfad5de5cfbfc50b50bfaf86ce1c020d5da6fb.png)

❓ **1** : how do I make the Context available in this scenario?  
❓ **2** : what do I risk with this structural approach and is it problematic?

---

<div class="post-metadata">

**Author:** ![exyi](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/exyi/32/9_2.png) [@exyi](https://forum.dotvvm.com/u/exyi)\
**Post date:** [February 19, 2024, 1:48pm UTC](https://forum.dotvvm.com/t/view-models-page-structuring-series-dotvvm-context-null-when-instantiating-markupcontrol-view-model-at-postback-in-command-handler/148/2 "2024-02-19T13:48:48Z")

</div>

The context is assigned automatically to the view models just before the Init phase, so if you create the nested model later than in the constructor, you have to assign the context yourself. Just do `new(clientHelper, ...) { Context = Context }`

(PS: yes it was a mistake to not require the context in the `DotvvmViewModelBase` constructor, but we are now not going to break every single view model because of this.)

> [@MarianV](#):
>
> ❓ **2** : what do I risk with this structural approach and is it problematic?

No, this shouldn’t be problematic.

---

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [February 19, 2024, 1:51pm UTC](https://forum.dotvvm.com/t/view-models-page-structuring-series-dotvvm-context-null-when-instantiating-markupcontrol-view-model-at-postback-in-command-handler/148/3 "2024-02-19T13:51:49Z")

</div>

> [@exyi](#):
>
> No, this shouldn’t be problematic.

😌 (at least 20 chars)
