views:

92

answers:

3

Right now, this is how we do things on our site at work: there's an .aspx page that does absolutely nothing in the codebehind, but contains the markup for the page in the Design View. Then we have an .asmx web service that receives requests with JSON content-type. These are called by the JavaScript in the page. This web service returns .NET objects serialized to JSON in response to these JavaScript Ajax HTTP POSTs.

I'd like to switch to MVC but am not sure to how switch this architecture.

Basically what we're doing is two things:

1) Replying to GET /MyPage.aspx with HTML markup that represents the page
2) Replying to POST /MyPage.aspx/WebMethodName requests with .NET objects serialized to JSON.

It seems like MVC would be a good way to eliminate the need for a Page object (again, the codebehind isn't used--only the HTML markup in the .aspx file is) and an .asmx web service. No?

What do I need to start changing to accomplish this switch? Is it straight-forward? Painful?

Someone at work already has an MVC page running in the same directory as my Web Forms .aspx and .asmx web service, but I don't see anything in the directory about Routes, so I'm confused. He's got a Views, ViewModels, and Controllers subdirectories.

A: 

You have two options:

  1. You can keep your web service and continue with the same ASPX as your view. This would require little or no modification of your ASPX (changing the master page)
  2. You can keep the ASPX and convert the ASMX to controller method which returns JsonResult
korchev
If I move my methods from the ASMX to the <tt>Controller</tt>, I should remove the <tt>[WebMethod]</tt> attribute from the method, correct?
JamesBrownIsDead
A: 

MVC can return Json, Plenty of examples on the web and SO. Did you google MVC JSON ?

TFD
A: 

So you have no real compelling reason to switch ? Asp.Net page has little to no overhead, it's compiled.

Just turn off things like viewstate and session if your not using them. Amount of effort = almost nothing.

Mischa Kroon