locked
MVC View User Control in a WebForms Web Application RRS feed

  • Question

  • User1563705749 posted

    We're using a 3rd party CMS that's using WebForms. To create custom content/code will you have to make them as Modules which is basicly UserControls.

    Would it be posible to create User Controls in MVC simlar way you would in Web Forms? How could I solve this?

    With MVC follows conventions on file structure and such. If posible would I think the best way would be to create a MVC project in the same solution as the CMS Web Application. Then refrence the new MVC project in the CMS web app. I'd then create the Controller and Model to the MVC View User Control in the MVC project, then create the MVC View User Control in the CMS Web App module folder and let it inherit the MVC Project

    Any replies and suggestions would be apriciated.

    Thanks,

    Arne

    Wednesday, July 11, 2012 9:44 AM

Answers

  • User-474980206 posted

    no can do.

    while a mvc view can host a webform user control (if webform view engine used), there is no postback support (which makes most user controls useless in MVC). but you can not create a webform usercontrols in MVC. if you are using javascript, you can call MVC json actions. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 11, 2012 11:22 AM
  • User1957004874 posted

    You should not be mixing both interms of user control both are build on the different assumptions and if you try to add something like this it will not be possible and will your app extremely dificult to manage.

    You can try running WebForms and MVC app side by side and thats based suited for scenarios like this.

    Thanks,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 11, 2012 10:00 PM

All replies

  • User-661350001 posted

    <% Html.RenderPartial("~/UserControls/Control.ascx"); %>

    Wednesday, July 11, 2012 10:34 AM
  • User-661350001 posted

    please check this

    http://blogs.msdn.com/b/davidebb/archive/2010/01/13/take-your-mvc-user-controls-to-the-next-level.aspx

    Wednesday, July 11, 2012 10:38 AM
  • User1563705749 posted

    Thanks for the reply Mudasir. The "Html.Partial("string");" requires the web page inherits "System.Web.Mvc.ViewPage" and this won't work when I'm using WebForms. I want to add a MVC User Control inside a Webform web page.

    I'm actually able to load MVC User Controls in a MVC Web Page the same as I'd do in a webforms site:

    <%@ Register TagPrefix="uc1" TagName="testUC" Src="UserControls/TestUC.ascx" %>

    <uc1:testUC ID="testofUC" runat="server" />

    Wednesday, July 11, 2012 10:59 AM
  • User-474980206 posted

    no can do.

    while a mvc view can host a webform user control (if webform view engine used), there is no postback support (which makes most user controls useless in MVC). but you can not create a webform usercontrols in MVC. if you are using javascript, you can call MVC json actions. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 11, 2012 11:22 AM
  • User1957004874 posted

    You should not be mixing both interms of user control both are build on the different assumptions and if you try to add something like this it will not be possible and will your app extremely dificult to manage.

    You can try running WebForms and MVC app side by side and thats based suited for scenarios like this.

    Thanks,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 11, 2012 10:00 PM
  • User1563705749 posted

    Thanks for the replies! I suspected it wasn't posible but I wanted to be sure. I was reading a few articles about mixing MVC and WebForms, and this would be a posibility. My problem is that the CMS is written in VB and I want to be using C#. With the other modules I've developed in to the CMS have I had the .aspx and .ascx files in the CMS Project folder while I've created a own project that contains the codebehind files that the .aspx, and .ascx files are inheriting (this way can I use C#). Is it posible to do something simlar with MVC? Having the View in the CMS project while having the controller and model in a different project? This would make things more tidy and clean.

    Thursday, July 12, 2012 3:03 AM