2

I have an asp.net-mvc site. I have a page with a grid of data on it and when I want to edit a row (by showing up a popup form). I have 2 options:

  1. Preloading and hiding the form on initial page load in a hidden div and then returning json from the server, binding all of the fields and attributes on the client side and then showing it.

  2. Returning PartialView() from the server of a PartialView() in which case all the binding is on the server side

It seems that this is decision of convinience versus performance.

Option #2 is much easier because I can do all the binding (and any logic) in C# but it seems like #1 would be much faster because I am not sending over all of that HTML over the network (just the json data). This assumes that the binding on the client side is going to be faster than the performance hit of the extra network hit.

Is there any other factors that I am missing in this decision to return json or a PartialView() when using asp.net-mvc to populate a form

9
  • 5
    That's the eternal question: Partial HTML vs JSON in AJAX. I don't think that you will get a definite answer to this. Both approaches are valid IMHO. Commented Apr 17, 2011 at 16:11
  • @Darin Dimitrov - i understand that either would work (listed above) but i just wanted to see if there was anything i was missing in terms of deciding which one was better for me in this situation. Commented Apr 17, 2011 at 16:17
  • @ooo, I think that you perfectly balanced the pros and cons of the two approaches: it's basically performance vs convenience of development. Commented Apr 17, 2011 at 16:18
  • @Darin Dimitrov - whats the best way to compare how much data comes over with json versus the partial view (in bytes). My concern is that migrate to the Json approach (versus the partial view with compression, etc. .) its hard to tell upfront how big of a savings the json will give me . . Commented Apr 17, 2011 at 16:26
  • @ooo, FireBug is a great tool for this job. Commented Apr 17, 2011 at 16:27

3 Answers 3

1

I think it is not a question of JSon or Partial View. Rather this is a question of approach. I would rephrase this as "Should I load the data on page in hidden divs or Should I load the partial view when needed"?

I would prefer the partial view as it doesn't make the initial load bulky and also helps to maintain clear seperation of what is rendered when.

Sign up to request clarification or add additional context in comments.

Comments

1

Another argument in favour of the json way is platform independence. If you do it the json way, it will be much easier later on to switch platforms, if needed. Partial views tie you tightly to the .NET platform. Json can be served from many different platform solutions, for example nodejs.

Comments

-1

For your particular scenario, i would recommend the partial view method.

here is a great article that discusses options for modal dialogs in mvc. the jQuery-UI dialog is the clear winner and his example works perfect.

http://www.codeproject.com/KB/ajax/jQuery-Modal-Dialogs.aspx

I also like the idea of loading partial views because u can strongly type them, which is always a good idea.

2 Comments

what is the reasoning of your recommendation. i am using jquery-ui dialog in either situation so i don't understand how that plays into it. the link again just gives different comparisons against other dialogs . .that is not my issue.
I didnt share the link for the comparison of the plugins- just for the demo code for the jquery dialog. He provides a clean, reusable method for loading partials into the modal dialog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.