I am working on a multi-page assessment form where the questions/responses are database driven. Currently I the basic system working with Html.BeginForm via standard ASP.Net MVC.
At this point in time, the key to the whole system is the 'Strongly Typed Partial Views'. When the question/response is read from the database, the response type determines which derived model is created and added to the collection. The main view it iterates through the collection and uses the 'Strongly Typed Partial Views' system of ASP.Net MVC to determine which view to render the correct type of response (radio button, drop down, or text box).
I would like to change this process from a Html.BeginForm to Ajax.BeginForm. The problem is I don't have a clue as to how to implement the dynamic creation of the question/response in the JavaScript/jQuery world. Any thoughts and/or suggestions?
Extra info:
The reason for the change is the complex real time skip-pattern (validation) which needs to happen. Some questions trigger skip-patterns. The skip-patterns determine the accessibility and values of other questions. When a user changes a question that triggers a skip-pattern, all the current answers need to be sent back to the server to be run through the rule engine.
One issue is that when an ASP.Net MVC input is set to read-only, it's value is not posted back. The solution is a hidden input with the current value. This hidden value needs to be managed by JavaScript in both the case the value is changed by the user or by the rule engine.
All in all, it seems very complex to manage. It seems more logical that the ASP.Net MVC code simply provide a JSON model and jQuery simply builds the forms in the browser and then calls either the save action or the skip-pattern validation action, passing it the JSON model. Seems to remove one layer of head-ache:)
Here is the current code to generate the dynamic form:
@using (Html.BeginForm(new { mdsId = @Model.MdsId, sectionId = @Model.SectionId }))
{
<div class="SectionTitle">
<span>Section @Model.SectionName - @Model.SectionDescription</span>
<span style="float: right">@Html.CheckBoxFor(x => x.ShowUnansweredQuestions) Show only unaswered questions</span>
</div>
@Html.HiddenFor(x => x.PrevSectionId)
@Html.HiddenFor(x => x.NextSectionId)
for (var i = 0; i < Model.answers.Count(); i++)
{
@Html.EditorFor(m => m.answers[i]);
}
}