tags:

views:

57

answers:

5

Hi All,

Can someone help me understanding Model-View-Controller method to be implemented on WebForms? I am confused on couple of things:

  • If we have ABC.ASPX and ABC.CS files, what is view? is it only ABC.ASPX file? or combination of .ASPX + .CS file?

  • do we consider ABC.CS file as controller? If no, will it be a seperate class for controller?

  • Does database connection and data retreival go into Model or a seperate class which will be called by Model?

Can someone give a simple example for implementing Model-View-Controller in webforms?

----Update---- Hi guys, my question is how to implement Model-View-Controller methodology using WebForms not about ASP.NET MVC2.0. I apologise for the confusion.

Cheers

+1  A: 

Here is a link that should explains it greatly: http://www.asp.net/mvc/tutorials/understanding-models-views-and-controllers-cs

pdiddy
Hi pdiddy, thanks for a quick reply but my question is about implementing M-V-C in webforms not ASP.NET MVC. Any suggestions on that??
Zinx
webforms are asp.net
pdiddy
ASP.NET MVC is an MVC framework you can use to build MVC webforms....
pdiddy
+1  A: 

As others have posted there is a lot of information out there on MVC, so I'll answer your question...

If we have ABC.ASPX and ABC.CS files, what is view? is it only ABC.ASPX file? or combination of .ASPX + .CS file?

It is both...however the .cs file is referenced as code behind but both make up the view.

do we consider ABC.CS file as controller? If no, will it be a seperate class for controller?

No, a separate class would be the controller.

Does database connection and data retreival go into Model or a seperate class which will be called by Model?

You could go either way. you could place this logic in the model, however you could also functionalize it out into services, which can then be called as needed by the model. IMHO the second route is the way to go, as I don't want to make my model dependent on external entities and it also makes testing the model easier, as you can separate out the services testing from the model testing.

Diagram can be seen here, which has some great imagery as reference points.

Aaron
+2  A: 

I guess I understood what you want to do: you want to implement a MVC architecture above an ASP.NET WebForms application. Fair enough.

All I can say is good luck! Me being there & done that. And how I regretted doing so... :P

Remember: ASP.NET WebForms is a huge abstraction, that tries to make the web into a statefull, event-based, windows-like environment, without any concern of decoupling whatsoever. So, trying to create an stateless, highly-decoupled and non-event-based architecture above that is, sorry to say, near insane.

Please, enlighten yourself and come to the real ASP.NET MVC world... :-)

PS: some people claim of having success implementing a MVP (Model-View-Presenter) architecture above ASP.NET WebForms. Shame on them (but you can try if you really want to)!

rsenna
Thanks for the comments rsenna :)
Zinx
@Zinx: You're welcome! Again, if you *really* want to go this way, take a look at the MVP architecture. It's bad, and it's a maintenance nightmare... But it's much better than trying real MVC over WebForms... At least you'll see some (marginal) use for those damn code-behind files...
rsenna
+2  A: 

Check out Web Forms MVP (Model - View - Presenter).

Martin