I am attempting to build an MVC form that uses ajax to post to a controller action which will return one of 2 partial views depending on the model state, and then perform a partial page update via jQuery. This part is all working fine.
The initial controller action that renders the page uses glass to populate form labels & service data to populate drop-down lists.
When posting the form data via ajax the controller action has no sitecore context so cannot re-render the glass model properties on subsequent requests. I don't really want to re-query sitecore & the call the external service on each attempted form post, so what would be the best approach in ensuring the sitecore & service data is available to the view model on each partial render?
My current thinking is to have separate renderings for experience editor (renders glass properties) & the published site (initial controller action populates view model with glass properties), and then when posting the form post the labels & drop-down options as hidden fields in order to be retrieved from the view model each time the partial page is reloaded.
With regular MVC you'd just use @Html.LabelFor but I naturally want that value to come from sitecore.
Read about the beginformroute & formhandler approach but this doesn't appear to offer anything & I've also read it cannot support returning partial views.
Looking for support on best practice here using sitecore v9.1
(typed on mobile device so cannot easily add code snippets. However don't believe this would have helped as it's just your regular MVC form cshtml, controller action returning a partial & js making an ajax call & updating a dom element via jQuery)
Thanks for any feedback & support on this 😊