HOWTO: implement a jQuery version of ASP.Net MVC "Strongly Typed Partial Views"

Posted by Sam Carleton on Stack Overflow See other posts from Stack Overflow or by Sam Carleton
Published on 2012-06-18T14:27:25Z Indexed on 2012/06/18 15:16 UTC
Read the original article Hit count: 245

Filed under:
|
|

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?

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]);
    }   
}

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about asp.net-mvc