fooberry

Sweetness without context.

Mixing WebForms and MVC

July 2nd 2010

We have a moderately large WebForms web application, but we are trying to transition to MVC. On the surface it sounds pretty simple. We can create controllers to do small functions of our page. we can be AJAXy if we so desire and all will be great.

Lets give it a try.  We want to add a customer search to our master page.  Simple enough right?

image

All I really need is a controller that redirects to our existing search page.  No problem. Seems simple enough. Let me code up the controller in a simpler, reduced test case.

Done in 15 minutes.

OK. Now we just need to drop a tiny form that posts to our controller on our master pagewait  a minute. WebForms has a HUGE form that takes up the entire page! I cant nest a form inside a form. This means I cant post inside the form to anywhere but the same form.

I know  what youre thinking. I shouldnt post to search anyway. I should get instead. Yes. I agree, but this example is contrived. I actually came across this problem when I wanted to create a controller that merged two customers together and redirect to the surviving customer. In that case we do want to postso bear with my invalid semantics.

Anyway. We cant POST. hmm..I guess we have to do something like this (remember in real life Im merging and not searching"):

[HttpGet] public ActionResult SearchViaGet(string searchTerm, bool isQuickSearch){}

It feels really nasty. What makes it even worse is we have to use Ajax to pull the values from the inputs and build the request URL. If they dont have JavaScript enabledoh well. No search for you!

I cant really think of a way around this. With MVC, and without the giant WebForms form, this page would comprised of several tiny forms. For now, the no JS problem isnt that big of a deal. The app is used by internal users only so if they dont have JS enabled we can just laugh at them until they either turn it on, or we feel bad that they dont know how to turn it on, and turn it on for them.

Where we do have a problem is when we try to use pages like this via our ancient mobile devices. We cant trust JS on those bricks and if I had to bet, there would be no search for them either.

blog comments powered by Disqus