HTML Submit button vs AJAX based Post (ASP.NET MVC)

Posted by Graham on Stack Overflow See other posts from Stack Overflow or by Graham
Published on 2010-04-02T14:11:35Z Indexed on 2010/04/02 14:13 UTC
Read the original article Hit count: 267

I'm after some design advice.

I'm working on an application with a fellow developer. I'm from the Webforms world and he's done a lot with jQuery and AJAX stuff. We're collaborating on a new ASP.MVC 1.0 app.

He's done some pretty amazing stuff that I'm just getting my head around, and used some 3rd party tools etc. for datagrids etc.

but...

He rarely uses Submit buttons whereas I use them most of the time. He uses a button but then attaches Javascript to it that calls an MVC action which returns a JSON object. He then parses the object to update the datagrid. I'm not sure how he deals with server-side validation - I think he adds a message property to the JSON object. A sample scenario would be to "Save" a new record that then gets added to the gridview.

The user doesn't see a postback as such, so he uses jQuery to disable the UI whilst the controller action is running.

TBH, it looks pretty cool.

However, the way I'd do it would be to use a Submit button to postback, let the ModelBinder populate a typed model class, parse that in my controller Action method, update the model (and apply any validation against the model), update it with the new record, then send it back to be rendered by the View. Unlike him, I don't return a JSON object, I let the View (and datagrid) bind to the new model data.

Both solutions "work" but we're obviously taking the application down different paths so one of us has to re-work our code... and we don't mind whose has to be done.

What I'd prefer though is that we adopt the "industry-standard" way of doing this. I'm unsure as to whether my WebForms background is influencing the fact that his way just "doesn't feel right", in that a "submit" is meant to submit data to the server.

Any advice at all please - many thanks.

© Stack Overflow or respective owner

Related posts about design-patterns

Related posts about asp.net-mvc