Allan2010 said:
Hi,
Can we use webform usercontrols (ascx files) in an MVC application?
A Web usercontrol would have its own MVC implementation, like a Web form
would have its own MVC implementation. If a usercontrol was accessing
data from a database, then it would use its MVC logic (separate logic)
like the Web form using its MVC logic to access the database that is
hosting the usercontrol, based on business rules used by each MVC
controller.
Generally, is there any online guide that explains best practices
when/how webfoms and MVC could be integrated and co-exist?
Maybe, you don't fully understand what the MVC design pattern is about.
What is Model –View- Controller?
(MVC) is an architectural pattern used in software engineering.
Successful use of the pattern isolates business logic from user
interface considerations,
resulting in an application where it is easier to modify either the
visual appearance
of the application or the underlying business rules without affecting
the other.
In MVC, the model represents the information (the data) of the application;
the view corresponds to elements of the user interface such as text,
checkbox items,
and so forth; and the controller manages the communication of data and the
business rules used to manipulate the data to and from the model.
http://en.wikipedia.org/wiki/Model-view-controller
The best practice is keep the UI dumb. The UI passes controls to the
'controller' through the 'view' where the controller works with the
controls to populate or extract data from the controls, based on
business rules.
You either start off using MVC for the project or you convert an
existing project to use MVC fully. It's either all or nothing in either
case.
However, for a given form or usercontrol, one may not be able to
implement MVC, which is based on a control's behavior of not working or
not being rendered using MVC. If this is the case, then things with a
control must be done at the UI at form or usercontrol level, which is
rare and mainly happens with 3rd party controls.
I don't use MVC myself. I use MVP which can be used for a Windows form
or a Web form application.
What is Model –View- Presenter?
MVP is a software pattern considered a derivative of the
Model-view-controller.
http://en.wikipedia.org/wiki/Model_View_Presenter