How to run NancyFx and Mvc5 with razor in one application?

107 Views Asked by At

I have working application based on NancyFx (1.4.3) and Owin. Now I want to remove NancyFx and replace (incrementally) with Mvc5. Those little steps allows me to port the whole project to the asp.net core in the future. :)

I can pass-through NancyFx specified paths to the MVC. My Owin Startup configuration looks like this:

public void Configuration(IAppBuilder app)
{
    app
        .MapSignalR()
        .UseNancy(o =>
        {
            o.PerformPassThrough = ctx =>
            {
                return ctx.Request.Path.StartsWith("/test");
            };
        })
        .UseStageMarker(PipelineStage.MapHandler)
    ;
}

Thanks to that I can run my application as usual. Only 'test' path will be handled by mvc controller:

public class TestController : Controller
{
    [Route("test")]
    public ActionResult Index()
    {
        return View();
    }
}

My main problem is with Razor which is configured like this: https://github.com/NancyFx/Nancy/wiki/Razor-View-Engine#letting-razor-know-what-base-type-your-views-use

and view rendered by MVC failed because:

The view at '~/Views/Home/Index.cshtml' must derive from WebViewPage, or WebViewPage<TModel>.

How to configure and run views from one folder for MVC and second folder for NancyFx?

1

There are 1 best solutions below

0
Jackdaw On

The view page should be inherited from System.Web.Mvc.WebViewPage. Make sure that the Index.cshtml is including the following line:

@inherits System.Web.Mvc.WebViewPage

The project should have reference to the System.Web.Mvc assembly too.