1

While trying to create my website as dynamic and with as few page reloads as possible, I've come to enjoy the use of partial views with AJAX - reloading or updating part of the page with AJAX GET or POST. However (being new to MVC in general) I've started wondering - is this the right approach.

Say there's the given scenario:

I have a table, on this table I have a button "View Details". When user clicks on this button, I want to retrieve information from the server and display it in a modal window.

I could do one of the following:

  • Create Details Partial View from model, execute AJAX GET to retrieve form from it on button click and place it inside modal window.
  • Create an action that returns JSON with necessary information, use AJAX to get it and populate modal form with it.

Which approach would be the correct one?

2 Answers 2

1

I always use Partial Views with AJAX actions. Let's be honest - I don't known what big HTML you should return to start thinking about backend performance.

Please remember that in both cases you will return text - either HTML or JSON. But the same performance is needed to get those values from the database (or from whatever place you are getting them).

What is more - concatenating strings and making HTML of that on the frontend isn't the base approach and should be used just in really special places.

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

Comments

1

Your question is actually opinion based. But I can say that it depends on situation.

If you have high perfomance BackEnd - it's better to render your view on controller and return html. It's the best option if you work with legacy browers like IE 8 for example.

If you don't have high perfomance BackEnd - you can return json or xml and then use js templates to make makup that you need.

2 Comments

Don't forget that "high performance" is also affected by user load. Plus, there's also caching to take into consideration, including varying by parameters. Not only is this Opinion Based, it's also Too Broad.
@krillgar I meant every word of it

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.