views:

311

answers:

2

How does the data go from the MVC to the browser and back again? Does it use Microsoft's own technology like ASMX or WCF or something completely different?

This sounds like MVC is using a ASMX Web Service they are using but I can't seem to find any documentation which gives the real answer.

+1  A: 

AJAX requests are performed in the page using normal HTTP request/response. That is, in javascript the client will create a AJAX request object, send it off to a URL and it gets back a string. If that string is json, it can be eval'd and become a live javascript object.

The philosophy of MVC is that all http requests go through controllers. WCF is only for other types of web services that where the client doesn't consume html-json-css-etc.

You can return JSON from a controller action using the Json(object model) method on System.Web.Mvc.Controller.

for example

ActionResult MyAction() {
    return Json(new { success=false, for_lunch="mmm, chicken"});
}

That will return the json your webpage can consume. So, that leaves the question - how does the browser call the MyAction for the json?

Several posts exist on this topic, and the first one i could find that did this was this post.

Hope that helps

CVertex
+2  A: 

The data from the MVC app <-> browser is just plain ole HTTP request/response data. To see what this raw data is, install Firebug or Fiddler on your PC and use that to show you the raw in and out data. It's all pretty simple.

WebForms use this same request/response model. the browser passes some info to the webserver (ie. the Request ... like .. i want to see http://www.mysite.com/foo) and the web server replies with some html, json, xml, binary data (for images), etc... this is the Response.

All browsers talk to all websites using this Request/Response model.

Now .. the difference with MVC and WebForms is HOW the webserver handles the request and how it generates the response. So they both follow the same concept, just handle it differently. For example, MVC uses controllers to determine what to show the user, while WebForms have a 'pages' which determine what data (for that page) to show.

So - in essence - you program your site to say:

  • If a user goes here, then show them this data.
Pure.Krome