如何启用MVC中的WebForms项目呢? [英] How to enable MVC in a WebForms project?

查看:250
本文介绍了如何启用MVC中的WebForms项目呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的web表单的项目。我从新增的NuGet MVC5,并添加以下内容:

I have an existing webforms project. I've added MVC5 from Nuget, and added the following:

_Viewstart.cshtml
Shared
   _Layout.cshtml
Areas
   Test
      Controllers
        TestController.cs
      Views
        Test.cshtml

我的控制器:

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



我的的Global.asax

        AreaRegistration.RegisterAllAreas();
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        RouteConfig.RegisterRoutes(RouteTable.Routes); 



然而,当我浏览到 /测试/测试,我得到404没有找到。我缺少什么?

Yet when I navigate to /Test/Test, I get 404 not found. What am I missing?

更新
我最终加入了一些事情的基础上的模板MVC5项目我的web.config我现在有被击中的控制器方法和视图位于。我处理别的事情,但现在我认为这是无关的MVC的配置,所以我认为这真的是容易。

UPDATE I ended up adding a few things to my web.config based on the templated MVC5 project and I now have the controller method being hit and the view being located. I'm dealing with something else now but I believe it's unrelated to MVC configuration, so I think it really is "that easy".

推荐答案

看着默认MVC5 web.config文件,添加以下到我的配置后,让我和运行:

After looking at the default MVC5 web.config, adding the following to my config got me up and running:

    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
  </dependentAssembly>

这篇关于如何启用MVC中的WebForms项目呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆