Is JSON better than partial views for all uses in ASP.NET MVC?

JQuery uses a utility called a data template that can display data through a template system.

My question is, are data templates better than renderpartial? Can someone explain their experience.

In my scenario, it would be better because they took another step for the developers and change custom, because it is easy to edit the template in js code instead of creating new partial views.

So what is the best option in asp.net mvc?

+4
source share
4 answers

I make the assumption that you are working with MVC and referring to partial views.

A partial view of the rendering on the server in one go is part of the page structure. Ajax calls load the page first and then add additional content later.

Partial browsing gives you SEO indexing. Ajax call gives you maximum page load speed.

Typically, you want as much as possible in the initial loading of the page, and then add dynamic content / feedback elements via ajax to improve the user experience.

+3
source

From my experience, I would just say yes. Now let me explain this a bit:

The biggest problem with RenderPartial and UpadtePanel (in WebForms ) is the simple fact that the actual html generation (i.e. output) is generated on the server side, so all you got on the client is to replace the updated DOM element with new content.

In this case, I do not like: the unnecessary amount of data transfer (sometimes in both directions) and the fact that the whole process of rendering the page is happening on the server side, which can translate into performance . Of course, for junior .net developers, this method seems like the perfect choice, because it is straightforward and does not require additional work or knowledge, but I would avoid it whenever I can.

Now the good thing with jQuery templates is that all communication with the server is done using JSON (most likely), and the amount of data is much smaller. And it also gives you the freedom to easily change the desired result without having to change the server logic (for example, relocate the application for each change).

+1
source

This is a useful and valid way to display part of a page.

I would say that partial views are more flexible because they are not dependent on javascript and can help your site be accessible if it needs to work with javascript and without it. Remember that you can load PartialView into a div from an action method that is called through AJAX.

However, if your site is biased for a rich user interface with multiple pages and most of the logic is controlled by javascript, then it would be wise to use jQuery templates. That would be a little faster due to less payload (although not so much, given that you usually just miss a little markup).

I usually look at partial views, as my javascript requires non-intrusiveness, and it would be much easier to use templates to work with templates instead of distracting partial views through AJAX.

+1
source

I did a quick Google search and found a lot of good articles about it, and they will give you more information and better understand, just take a look at the first search result.

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=jquery+template+vs+partial+views

Also consider this question from stackoverflow:
JQuery vs. partial views in ASP.NET MVC

0
source

Source: https://habr.com/ru/post/1347047/


All Articles