0

I have a page that has a "prev" and "next" day button, and rather than reload the entire page, I simply do an ajax call to a controller that returns the entire partial view, which I replace the div with.

$("#divId").html(ajaxResponse);  

Pretty simple.

However, I'm finding that this partial view is vastly more data than I need (html doesn't change at all, just the data) and it's causing slowness on mobile browsers.

My question is, is there a tool out there that will let me return a JSON representation of the model data and refresh all the values on the page automatically?

For example, say I have:

@Html.InputFor(x => x.FirstName)

and the JSON returns

{ FirstName: 'Henry', LastName: 'McLeery' }

Is there a library available that can automate the process of doing:

$("#FirstName").val(ajaxResponse.FirstName);
$("#LastName").val(ajaxResponse.LastName);
etc...

?

1
  • You already answer your question, last code. You need to wrap it into $ajax success: function(ajaxResponse) { your code } Commented Aug 6, 2014 at 8:49

1 Answer 1

0

Take a look at Angular.js. Angular is a JavaScript framework which uses the mvc pattern. After binding UI elements to your model the displayed data changes automatically when updating your model. Angular offers a nice api to consume ajax requests with json data.

Look at this: Get and update json using angular.js

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

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.