Retrieve post data in ASP.NET MVC
Retrieve post data in ASP.NET MVC
We have ASP.NET MVC application. We are not using your .NET dll as they communicate directly (at least as shown in your examples and manual) to the tables. We have a data layer with Model that we want it to talk to (see code below). The only other option for us, is to retrieve the post data and bind it manually to our object model.
Could you provide us with the JSON structure that the data is submitted back to the server? we would like to build a model that mimics this JSON structure so that we can use ASP.NET MVC built in actions to retrieve the data on server side.
Here is sample server side code that we would like to use. We would like to know how to construct the Person object so that the POST will work in ASP.NET MVC.
[HttpPost]
public ActionResult Save(Person person)
{
//Here we would access the person object to get the data
string name = person.name;
//save this to our data service layer
_dataService.SavePerson(person);
}
///current Person Model
public class Person
{
public int ID {get; set;}
public string name {get; set;}
public string lastname {get; set;}
}
Answers
Hi,
I've just replied to the PM, but I thought I'd repost it here in case anyone else finds that it might be useful.
Thanks for your message. The format of the date sent to the server is documented here. One thing to keep in mind is that Editor supports multi-row editing, so the structure of the data reflects that. If that isn't suitable for your use case you can enable the legacy format using the
legacyAjax
option which is a bit easier for single row editing.Another option that might be of interest is the
ajax.data
option which can be used as a function to modify the data that is submitted to the server, including the ability to just have it sent JSON in the body, so you could use something like Newtonsoft on the server-side to parse it out.Finally, although you might not want to use the DataTables.dll to write to the tables directly, you could still use it to serialise the data submitted by the client-side through its
DtRequest
class - specifically theHttpData
method which will give you back the data submitted in an untyped Dictionary (<string, object>).Regards,
Allan