Model:
public class Product { public int ProductID { get; set; } public string Name { get; set; } public string ProductNumber { get; set; }
public List<ProductLocations> Locations { get; set; } }
public class ProductLocations { public string Address { get; set; } }
Controller
[GridDataSourceAction] [HttpPost] public ActionResult PostDataMethod3(Product Param1, string Param2, string Param3) { try { List<Product> products = new List<Product>();
products.Add(new Product { ProductID = 1, Name = "Product 1", ProductNumber = "12345" }); products.Add(new Product { ProductID = 2, Name = "Product 2", ProductNumber = "12346" }); products.Add(new Product { ProductID = 3, Name = "Product 3", ProductNumber = "12347" }); products.Add(new Product { ProductID = 4, Name = "Product 4", ProductNumber = "12348" }); products.Add(new Product { ProductID = 5, Name = "Product 5", ProductNumber = "12349" });
return View(products.AsQueryable()); } catch (Exception ex) { string error = ex.Message; return null; } }
AJAX call
var appJson = { "Param1": { "ProductID": 1, "Name": "test product", "ProductNumber": "P123", "Locations": [{ "Address": "Address1" }, { "Address": "Address2" }]}, "Param2": "Param2", "Param3": "Param3" };
$('#postData3').click(function (e) { e.preventDefault();
$.ajax({ url: '@(Url.Action("PostDataMethod3"))', type: 'POST', traditional: true, contentType: "application/json", dataType: "json", data: JSON.stringify(appJson), success: function (response) { alert('Succcess'); $('#grid').igGrid({ dataSource: response }).igGrid("dataBind"); }, error: function (xhr, ajaxOptions, thrownError) { alert('Failure - ' + xhr.responseText); $('#grid').igGrid({ dataSource: null }).igGrid("dataBind"); } }); });
Eroor:
2022infragisticerror.igGridQueryStringToJson.zip
Hello Anitha,
Thank you for the provided sample!
I’ve been looking into your question and after an investigation what I could say is that the initial error is thrown because the “appJson” variable was not being parsed properly. It can be passed to the “data” property without being stringified. Another issue I have found is that the “PostDataMethod3” never receives its parameters even if the grid loads, so changing the code in the following way provides the desired results:
var appJson = {
Param1: { "ProductID": 1, "Name": "test product", "ProductNumber": "P123", "Locations": [{ "Address": "Address1" }] },
Param2: { "ProductID": 2, "Name": "test product", "ProductNumber": "P123", "Locations": [{ "Address": "Address1" }] },
Param3: { "ProductID": 3, "Name": "test product", "ProductNumber": "P123", "Locations": [{ "Address": "Address1" }] }
}
…
$.ajax({
url: '@(Url.Action("PostDataMethod3"))',
type: 'POST',
data: appJson,
success: function (response) {
alert("Success");
$('#grid').igGrid({ dataSource: response }).igGrid("dataBind");
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Failure - ' + xhr.responseText);
$('#grid').igGrid({ dataSource: null }).igGrid("dataBind");
});
Attached could be found my sample for your reference. Please test it on your side and let me know how it behaves.
Regards, Aleksandar Atanasov,
Infragistics.
Index.zip
Can you check this as priority
No working it's same issue as earlier
Note: which is working on our old Infragistics.Web.Mvc 2017.
Not working Infragistics.Web.Mvc 2022 we received recently for upgrade.
attached dll for your reference.
dll.zip
Controller:
============================
[GridDataSourceAction] [HttpPost] public ActionResult PostDataMethod3(Product Param1, Product Param2, Product Param3) { try { List<Product> products = new List<Product>();
Ajax
=====================
//json2 var appJson2 = { "Param1": { "ProductID": 1, "Name": "test product", "ProductNumber": "P123", "Locations": [{ "Address": "Address1" }] }, Param2: { "ProductID": 2, "Name": "test product", "ProductNumber": "P123", "Locations": [{ "Address": "Address1" }] }, Param3: { "ProductID": 3, "Name": "test product", "ProductNumber": "P123", "Locations": [{ "Address": "Address1" }] } }
$.ajax({ url: '@(Url.Action("PostDataMethod3"))', type: 'POST', data: appJson2, success: function (response) { alert("Success"); $('#grid').igGrid({ dataSource: response }).igGrid("dataBind"); }, error: function (xhr, ajaxOptions, thrownError) { alert('Failure - ' + xhr.responseText); $('#grid').igGrid({ dataSource: null }).igGrid("dataBind"); } }); });
viewmodel
================================