dimanche 23 août 2015

How to save data dynamically from a View in MVC5

I want to build a Questionnaire MVC5 project. I have a MSSQL database with several tables like: Employee, Questions, Results ...

I made a new MVC5 project, I add it the model base on my database and I manage all CRUD operations need it.

Now I made an view for Questionar :

@model IEnumerable<ChestionarMVC.Models.FormQuestion>

@{
    ViewBag.Title = "Chestionar";
}

<h2>Chestionar</h2>

    @foreach (var item in Model)
    {
   @Html.Partial("_Chestionar",item)
    }
<input id="Submit1" type="submit" value="submit" />

And a partialView to show each question with 2 text area, one for the answer and one for some aditional info :

@model ChestionarMVC.Models.FormQuestion

<table border="1" style="width:100%">

        <tr>
            <td>
                @Html.DisplayFor(modelItem => Model.Question)
            </td>

        </tr>
        <tr>
            <td>
                Raspuns <br />
                <textarea id="TextArea1" rows="2" cols="80" style="width:800px; height:100px;"></textarea>
            </td>
        </tr>
        <tr>
            <td>
                Document <br />
                <textarea id="TextArea2" rows="2" cols="80" style="width:400px"></textarea>
            </td>
        </tr>
</table>

Now I want to save in the tblResults the QuestionID, Answer and Document. In webforms I made a usercontrol, then I used Foreach usercontrol , and saved to database.

In MVC how can I save all?

Aucun commentaire:

Enregistrer un commentaire