I have a HTML form that has two DIVs, one DIV is a fixed area this means that the inputs are not dynamic, and the second DIV is dynamic this means that I have a button that can clone the DIV as many times as a I want.
This is the jquery clode for cloning a new DIV:
$('#btn-addsection').click(function (e) {
var me = $(this);
e.preventDefault();
var lastRepeatingGroup = $('.repeating-section').last();
var cloned = lastRepeatingGroup.clone(false)
cloned.insertAfter(lastRepeatingGroup);
var attrs = ['for', 'id', 'name'];
var tags = section.find('input, label'),
idx = section.index();
tags.each(function () {
var $this = $(this);
if ($this.is('input')) {
$this.val('');
}
$.each(attrs, function (i, attr) {
var attr_val = $this.attr(attr);
if (attr_val) {
$this.attr(attr, attr_val.replace(/_\d+$/, '_' + (idx)))
}
})
})
});
The above code will clone the DIV and will add a underscore "_" plus the next index to the field so I can identify it as a field for a second or third, etc. DIV cloned.
When I post to server I use:
var formData = $('#form-newquote :input').serializeArray();
This is my Save method on server:
public JsonResult SaveQuote(QuoteModel model)
{
var response = this.JsonResponse;
response = new JsonResponse
{
data = null,
message = string.Empty,
num = 0,
success = true,
code = null
};
return Json(response, JsonRequestBehavior.AllowGet);
}
This is my QuoteModel
:
The red mark is where I will many as many cloned items. My problem is how to send from jquery to server all my dynamic fields so on server I can map them to my QuoteSelectionMode
object.
Any clue?