Friday, 23 August 2013

ASP.Net MVC 4 - How to dynamically add row to html table

ASP.Net MVC 4 - How to dynamically add row to html table

I got a ASP.net MVC 4.0 web application which enable user to dynamically
add rows to html table.
In my view:
$('.del').live('click', function () {
id--;
var rowCount = $('#options-table tr').length;
if (rowCount > 2) {
$(this).parent().parent().remove();
}
});
$('.add').live('click', function () {
id++;
var master = $(this).parents("table.dynatable");
// Get a new row based on the prototype row
var prot = master.find(".prototype").clone();
prot.attr("class", "")
prot.find(".id").attr("value", id);
master.find("tbody").append(prot);
});


Model.ChillerDetails)%> //referring to the template



**In my template:**
" %>
m.ChillerAge) %>
m.ChillerBrand) %>
m.ChillerCapacity) %>
m.ChillerRefrigerant) %>

"/> "/>

**In my Model:**
public class AddHealthCheckFormModel{
public List ChillerDetails { get; set; }
}
public class ChillerPlantDetails
{
//[Required(ErrorMessage = "Please enter Chiller Capacity.")]
[Display(Name = "Chiller Capacity")]
public string ChillerCapacity { get; set; }
//[Required(ErrorMessage = "Please enter Age of Chiller.")]
[Display(Name = "Age of Chiller")]
public string ChillerAge { get; set; }
//[Required(ErrorMessage = "Please enter Chiller Brand.")]
[Display(Name = "Chiller Brand")]
public string ChillerBrand { get; set; }
//[Required(ErrorMessage = "Please enter Chiller Refrigerant.")]
[Display(Name = "Chiller Refrigerant")]
public string ChillerRefrigerant { get; set; }
}
Now the question comes to how can I capture the data in the dynamically
added rows into my controller and save into database?
Thanks.

No comments:

Post a Comment