Can we user webform usercontrols or server controls in MVC?

  • Thread starter Thread starter Allan2010
  • Start date Start date
A

Allan2010

Hi,

Can we use webform usercontrols (ascx files) in an MVC application?

Generally, is there any online guide that explains best practices when/how
webfoms and MVC could be integrated and co-exist?

Thank you,
Allan
 
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
 
Hi Allan,

The two kinds of user control is different.
The user control in webform is of type System.Web.UI.UserControl while the
one in MVC is of type System.Web.Mvc.ViewUserControl which is inherited
from System.Web.UI.UserControl.
Generally speaking, we need to import the following statement in page to
define a mvc uer control .

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

Besides there is no code behind for MVC user control and no any server
control conception for MVC.

If you want to mix the traditional ASP.NET and the ASP.NET MVC, you can
take a look at the following articles.
http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc

http://blogs.imeta.co.uk/MGodfrey/archive/2009/03/31/663.aspx

--
Sincerely,
Zhi-Qiang Ni
Microsoft Online Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
 
Hi,

Can we use webform usercontrols (ascx files) in an MVC application?

Generally, is there any online guide that explains best practices  when/how
webfoms and MVC could be integrated and co-exist?

Thank you,
Allan

Hello:
An MVC form don't have a runat="server" tag, MVC page cicle is
completely different from classic asp.net. So, the short answer is no,
you can't use regular asp.net server controls in MVC pages.
 
Back
Top