Understanding RequestModelAccessor.RequestModel.SearchQuery.Clone()

Hello,

The problem
I am building a react component with a few drop down fields. Each onChange of a dropdown calls the server which in turn calls an external api for information which populates the next dropdown. Each of the server calls are HttpPost.

Now, when the last dropdown changes, I receive article numbers of the products which should be displayed as search results. For this, I planned to use SearchResultViewModelBuilder.Build() which would build my product objects and return a SearchResultViewModel for me to return to my view.

However, when Build() runs, it tries to get a SearchQuery by calling _requestModelAccessor.RequestModel.SearchQuery.Clone() and this throws a nullreferenceexception because RequestModel is null. The RequestModel object is disposed in RequestModelHandler when the page is finished loading, and I cannot use it to build my request. If I comment out the row in RequestModelHandler where RequestModel = null, I can successfully build the request.

The question
Can I somehow keep the RequestModel object from disposing until after I have finished user input?

Litium version: 7.1

You need to add the client context on the request if that not already is there (some information about the context can be found in this thread Moving ClientContext to external call). You also need to ensure that you are building all the data that you are returning before you return result as an IHttpActionResult. If you return an object that not is populated like an IEnumerable<T> that will be populated when it is executed you are out to have trouble and should change them to be populated inside the execution block (example adding .ToList() of them so they are populated directly).