In my project when I trigger with this problem I'm starting to use ajax query, which hit after user away from textbox. It's not clearest solution but works for me. Also you need to generate special Id in partial view for each group element. Smth about:
function eduFacilityTableSave() {
$('#eduFacilityTable tr input[type="text"],#eduFacilityTable tr select').change(function () {
var parId = $(this).parent().parent().attr('id');
var parentName = parId.replace(/\d+/g, '');
var parentId = parId.replace(/\D+/g, '');
var id = $(this).attr('id');
var text = $(this).val();
//alert(text);
$.ajax({
type: "POST",
//contentType: "application/json; charset=utf-8",
url: "/Form/SaveFromForm/",
data: { id: id, parentId: parentId, parentName: parentName, text: text },
dataType: "json",
success: function (data) {
//
}
});
});
}
public JsonResult SaveFromForm(string id, string parentId, string parentName, string text) {
if (parentName == "eduFacility") {
var edufacility = _repository.GetEduFacilityById(Convert.ToInt32(parentId));
if (id == "EntryYearId") {
edufacility.EntryYearId = Convert.ToInt32(text);
}
if (id == "FinishYearId") {
edufacility.FinishYearId = Convert.ToInt32(text);
}
if (id == "FullName") {
edufacility.FullName = text;
}
if (id == "Speciality") {
edufacility.Speciality = text;
}
if (ModelState.IsValid) {
_repository.UpdateEduFacility(edufacility);
_repository.Save();
}
}
return Json("Success", JsonRequestBehavior.AllowGet);
}