I have a simple Widget that I've created using a ContentPart. The ContentPart has the appropriate Driver, the Widget can be placed anywhere in my Orchard site and everything works great! The Widget needs to capture some data from the user, validate it, process it and then display a success response in the Widget.
To achieve this I've defined a controller that accepts a POST request that will process the Model and return the same MyForm view if it is invalid or return the FormSuccess view if it's valid. The Widget Part template uses @Html.Partial("MyForm")
to display the MyForm view that contains an Ajax form that will update it's containing div with the POST response. The controller will return the MyForm view or the FormSuccess view depending on the data.
The problem that I'm having is that my designer needs to override the partial views for the MyForm view and FormSuccess view, he can easily override the Part display template but not the partial views.
I think the reason that this isn't possible at the moment is because I'm using @Html.Partial("MyForm")
. I've found that if I use @Display(New.MyForm())
instead, I can override the MyForm view by creating a file called MyForm.cshtml in the Views folder for the current theme, this is exactly what I need, but how do I do the equivalent for @Display
in the controller action?
At the moment I'm doing return this.PartialView("MyForm", model)
or return this.PartialView("FormSuccess")
which is going to use the original views and not the overridden ones. I've noticed that there is a ShapeResult but I'm not sure if this is the right thing to do and I don't know how to generate the dynamic constructor parameter. Also ideally I need the MyForm view to have a strongly typed model so that I can use the HtmlHelper methods LabelFor, TextboxFor and ValidationMessageFor which isn't possible when the model is a dynamic?
Has anybody done something like this before or can anyone offer any guidance?
Thanks, Jason