How to use DataTable Editor with MVC Model Binding?

How to use DataTable Editor with MVC Model Binding?

rprahaladrprahalad Posts: 20Questions: 5Answers: 0

Hi All,

We just procured a license for the DataTable editor and realized that we have to literally learn it's way to code even on the server side (Controller). Does it mean that I can't use the ASP.NET MVC way of model binding and Model classes decorated with DataAnnotations and submit the data?

Are we supposed to learn to code it now the Editor way? Because in the only example I saw on the EDitor site, there was a line for 'Request.Form' as well.

Just wanted to confirm that that's how we have to do it!

Like for example, currently my controller method used to paint the Table is this. As we can see there is a service layer which returns a List<ClientModel> and the ClientModel class has DataAnnotations that says the Name is required etc.

        var clients = new ClientService().GetAllClients().OrderBy(a => a.Name).ToList();           
        return Json(new { data = clients }, JsonRequestBehavior.AllowGet);

If I am writing the Editor code for this, can you please let me know how to start writing it? I still need to use the DataAnnotation Validation of ViewModel objects and not use the Editor's. Because that would mean like learning a new language and not using MVC's built in plumbing, which is highly undesirable, as the control should work with MVC and not the other way around.

I am missing something here for sure. Please confirm before we can even start.

Thanks

Answers

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    Yes, Editor's libraries do not work with an MVC model in the sense of GetAllClients (etc). Rather it will directly integrate with the database, generating the SQL required, through and ADO.NET connection.

    That's not to say you can't use your MVC model - you can and our client / server communication is fully documented, but you would need to write the server-side integration needed to interface between the data submitted (and expected in return) and your libraries / models. The .NET libraries we provide wouldn't help with that I'm afraid.

    Regards,
    Allan

  • rprahaladrprahalad Posts: 20Questions: 5Answers: 0

    Got it. Thanks Allan for confirming.

This discussion has been closed.