1

What is the preferred method of returning data from a class, through JSON and then constructing the HTML on the clientside, or by constructing the HTML in the returned data?

Thanks

4 Answers 4

3

JSON is the preferred method. It makes for a more scalable solution which is not dependent on the consumer of the services that you are using.

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

Comments

2

That depends on the nature of your application. If you want to build a list, for example, that makes sense to have a web method return a JSON, have a template of the list item and construct the DOM using jQuery or something similar (or even by hands). However, sometimes that may make sense to return an HTML (e.g. if you need to get a themed template of the list item), but then you will once again return to JSON for data.

Comments

0

The MVC framework provides extensive support for producing HTML server side, using controllers and views to give structure. I would suggest some reading on this, http://www.asp.net/mvc.

3 Comments

Even though a specific framework makes it easier to generate markup server-side, it is not necessarily always the BEST option. In a technology-agnostic and interoperable environment, deriving a scalable solution is always the best option - which is JSON in this case.
Thats a fair point and why I edited this post to intend it as more of a suggestion for further reading, than an opinion. It is going to depend very much on what is actually being attempted.
I saw the edit. Wasn't try to sound antagonistic, so excuse me if it did.
0

Your question can pretty much be translated to: "Do I choose ASP.NET WebForms or ASP.NET MVC?" in terms of Microsoft technologies. In my honest opinion WebForms or constructing HTML on the server is a bit outdated and the more modern approach, the MVC, is better in terms of scalability as mentioned above. Delivering JSON to the client allows you to reuse data services across your views (pages) and render different front-end depending on how your application evolves, which the server-side rendered HTML is hard to modify.

Comments

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.