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...

?

Scottie
  • 11,050
  • 19
  • 68
  • 109

1 Answers1

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

Community
  • 1
  • 1
jkone
  • 76
  • 2