views:

46

answers:

2

does it reload the entire page or does it have the intelligence to only send the necessary js to update the needed parts of the page that have changed?

if it does the latter that would be a god send, however im probably being dreamful. it probably returns the entire view without any regard, right?

edit: answer seems to be no, everything is returned.

edit added: do you think it would be difficult to write a framework where mvc compares last html it output to the current html we want to output, and instead of sending the entire html, figure out what has changed and generate js code that will do the updating as compared to previous html? (presuming nothing was manually changed on the client using js)... maybe an idea for a codeplex project? or maybe something like this exists?

+1  A: 

Well, it entirely depends on how you do it.

You can return anything you want, when using ajax its common to return your data in JSON. Example:

public ActionResult GetCustomers()
{
    if(Request.IsAjaxRequest)
       return Json(db.GetCustomers());

   return View(db.GetCustomers());
}

This will return all customers Json encoded if the request was made using Ajax.

You can stil return anything you want, if you want to return a view, it's just to

return View(model);

If you dont want to return the layout (master page), just return the MasterPageFile directive from your view.

And no, it does not reload the entire page, that's why it's called *A*jax.

alexn
hi, - i know i can custom implement these, but im specifically wanting to know what happenes when the index is returned via ajax, does it return the entire index html or a smart auto generated js to do the updating on its own. i know i can write js to do the updating on the client, but hoping now to.
Erx_VB.NExT.Coder
Well, i might not understand what you're asking. Asp.net MVC is not returing any JS at all.
alexn
thanks, that answered my question
Erx_VB.NExT.Coder
Great, please mark my answer as answered to help others.
alexn
A: 

Frankly, what happens on the client side is of no concern to MVC. :-) It does not know whether the call was made by the browser engine or the ECMA script.

And since you are asking about Ajax call, the responsibility with dealing with the result falls onto your script (or whatever JS framework you're using).

Franci Penov
do you think it would be difficult to write a framework where mvc compares last html it output to the current html we want to output, and instead of sending the entire html, figure out what has changed and generate js code that will do the updating as compared to previous html? (presuming nothing was manually changed on the client using js)... maybe an idea for a codeplex project? or maybe something like this exists?
Erx_VB.NExT.Coder
You are doing it way too complicated. It's gonna be complex and fragile. Besides, you will hit the problem of how to identify the previous response with the current request; how many responses you need to keep, where to store them and when to remove them.
Franci Penov
all u need for response identification is an id, i wouldn't write thsi just for my solution, but just a general thought, fantasy idea... would you use such a thing if it existed?
Erx_VB.NExT.Coder
Lol, no, I wouldn't use it, for the reasons above and others. :-)
Franci Penov
well you only need to store the 'last generated html' as our cache, then at another trip, you send the js that does the updating and you store the js with the html output from the previous, and keep doign that until of course if the js generated is greater than the html that would be generated, you just send the updated html instead of the js, and as usual, keep that as out last output cached, and keep going like that. these are just obvious/common methods that i'd thought would go without saying. any thoughts?
Erx_VB.NExT.Coder