This question already has an answer here:
- POST a form array without successful 2 answers
Users can take multiple courses and they can fill the course details in the text box by adding them on button click.
Had searched and got these two links but didn't understood how to use it in my situation.
Adding dynamic controls and get their values
Adding dynamic controls and get their values in MVC
I am using jquery to add text box on client side.
<script>
$(document).ready(function () {
$("#txt").click(function () {
var $ctrl = $('<input/>').attr({ type: 'text', name: 'text', value: '' }).addClass("text");
$("#holder").append($ctrl);
})
});
The text boxes are added successfully on each button click like if a user wants 5 text box then they can do that,but how to get all the 5 text box values in a model so that I can save them in 5 rows in my table
<div style="display:inline">
<input type="button" id="txt" value="Add TextBox" style="" />
</div>
<div id="holder">
</div>
Model
public class tblCourse
{
public int Id { get; set; }
public string CourseName { get; set; }
}
Viewmodel
public class VMStudentDetails
{
public List<tblStudents> students { get; set; }
public tblStudentDetails StudentDetails { get; set; }
public List<tblCourse> Course { get; set; }
}
Action
[HttpPost]
public ActionResult Save(VMStudentDetails model)
{
return View();
}
View
@using (Html.BeginForm("Save", "Student", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<input type="submit" value="Upload" />
}
Aucun commentaire:
Enregistrer un commentaire