Enable MVC 3 Views in a Web Forms Application

I am developing one new area of โ€‹โ€‹a fairly large web application using MVC3 and Razor, where the rest of the application is based on ASP.NET 4 Web Forms. Can I include my MVC components in this application and what do I need to do for this?

+3
source share
3 answers

http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc

This should lead you to the right road. If it were me personally, I would add a new project to your solution, which is MVC, then you can just configure the virtual directory in IIS / MVCApp

+3
source

, WebForms MVC , . , WebForms, MVC, . , , :

  • MVC AJAXified, AJAX .
  • - "" -, MVC , WebForms.

.

+4

, , MVC- -.

public class HelperFactory
{
    private class FakeController : Controller
    {
    }

    private class FakeView : IView
    {
        public void Render( ViewContext viewContext, TextWriter writer )
        {
            throw new NotImplementedException();
        }
    }

    public static HtmlHelper<TModel> GetHelper<TModel>()
    {
        //HttpContextBase context = new HttpContext( HttpContext.Current );
        FakeController controllerBase = new FakeController();
        RouteData rd = new RouteData();
        rd.Values.Add( "controller", "Fake" );
        RequestContext requestContext = new RequestContext( new HttpContextWrapper( HttpContext.Current ), rd );
        ControllerContext fakeContext = new ControllerContext( requestContext, controllerBase );
        ViewDataDictionary vdd = new ViewDataDictionary();
        ViewContext viewCtx = new ViewContext( fakeContext, new FakeView(), vdd, new TempDataDictionary(), requestContext.HttpContext.Response.Output );

        return new HtmlHelper<TModel>( viewCtx, new ViewPage() );
    }
}
0

Source: https://habr.com/ru/post/1780478/


All Articles