How to enable MVC in a WebForms project?(如何在 WebForms 项目中启用 MVC?)
问题描述
我有一个现有的网络表单项目.我从 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);
然而,当我导航到 /Test/Test 时,我得到 404 not found.我错过了什么?
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>
这篇关于如何在 WebForms 项目中启用 MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 WebForms 项目中启用 MVC?
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
