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?
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
