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?
基础教程推荐
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
