I have to send data from view to Action so that I could access it as Model
My scripts:
loadData(Element);
var id = $(this).parent().closest('div').attr('id'));
$.ajax({
url: "/FormsCreation/EditLoadForm/"+ id +"?otherparameters...",
type: 'GET',
dataType: "json",
data: JSON.stringify(data),
success: function (result) {
$('#modalContent').load(result);
$('#modalDiv div[class="modal-header"]').find('h3').text('Edit DataEntry');
$('#modalFooter').attr('class', 'modal-footer hide');
$.validator.unobtrusive.parse($("#modalContent form"));
$('#modalDiv').modal({
backdrop: 'static',
keyboard: true
}, 'show');
loadDDL();
loadCheckBox();
EditbindForm(this);
}
});
function loadData(edit) {
var tds = edit.find('td');
var type = new Array();
var fieldid = new Array();
var val = new Array();
for (var i = 0; i < tds.length - 1; i++) {
var chldrn = tds.eq(i).children('input');
for (var j = 0; j < chldrn.length; j++) {
type.push(chldrn.find('[name*="field_type"]').eq(j).val());
fieldid.push(chldrn.find('[name*="field_id"]').eq(j).val());
val.push(chldrn.find('[name*="value"]').eq(j).val());
}
}
var fielddtls = {
field_id: fieldid,
field_type: type,
value: val
};
var data = {
formfields: fielddtls
};
}
I get Values from required fields and fill it into "data" and i wish to pass it to the 'GET' Action in Controller as below:
public ActionResult EditLoadForm(int formid, int id, string type, string ImageName = "None", FormsCreationModel data = null)
{
ViewBag.SubFormId = id;
var moditem = new FormsCreationModel();
if (type == "Form")
{
moditem = formRepository.GetFormValues(formid, id);
}
else
moditem = formRepository.GetTempValues(formid, ImageName);
moditem.type = type;
return View(moditem);
}
My Model
public class FormsCreationModel
{
public int form_id { get; set; }
[Display(Name="Form Name")]
public string form_name { get; set; }
public string type { get; set; }
[Display(Name="Batch No")]
public int BatchId { get; set; }
public string ImageName { get; set; }
public string UserId { get; set; }
public int SubId { get; set; }
public IList<ListFormDataModel> ListData {get;set;}
public IList<FormDetailsModel> formfields { get; set; }
public string loadType { get; set; }
}
Some Referred Links:
How to send data back to controller in MVC using knockout
How to pass multiple parameters in json format to a web service using jquery?
Post an Array of Objects via JSON to ASP.Net MVC3
Question
My Question is that whether i am doing it right? Right now I am getting "Internal Server Error 500". I want to make sure that I am in the right direction and also to know any other possibilities such using Knockout. Please guide me on this. I am Newbie towards both MVC 4 and javascripts, so need a little detailed answer rather than precise one..