Wednesday

asp.net mvc ajax post model

If model contain variable of class Class1 with properties Property1,Property2.
Submitted parameters must be named:
"Class1.Property1"
"Class1.Property2"

If model has property as List<Record> submitted values must be :
"Class1[0].Property1"
"Class1[0].Property2"
"Class1[1].Property1"
"Class1[1].Property2"
"Class1[2].Property1"
"Class1[2].Property2"

Here are samples of two functions that creates this values dynamically before submitting form.

     
//this function create parameters for sending them over AJAX
function ConvertJSONIntoPostableHTML() {
var params = {
param1 : 'myvalue',
};

if (Jsonrecord != null) {
for (var i = 0; i < Jsonrecord.length; i++) {
var rec = Jsonrecord[i];
$.each(Object.keys(rec), function(j, value) {
params["Records[" + i + "]." + value] = rec[value];
});
}
}

return params;
}


        

//this function add parameters to form , then form can be submitted
function SelectedNodes(frm) {
$(".tslct").remove();
var i = 0;
$.each(myJsonCollection, function () {
var obj = "Nodes[" + i + "].";
addElem(frm, obj + "Id", this.Id);
addElem(frm, obj + "Value", this.Type);
i++;
}
);
}


No comments:

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...