Car*_*l R 5 c# asp.net-mvc asp.net-mvc-5
我通过创建新的ASP.Net Mvc 5框架然后放入内容来升级站点。目前,除了强类型视图之外,其他所有方法似乎都可以正常工作。所有Model属性访问均失败,并且显然使用了非通用控制器。
例:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MySite.Models.MyViewModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h1><%= Model.Title %></h1>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
我得到错误``对象''不包含``标题''的定义并且没有扩展方法...
在模型上进行定义将我带到这里:
namespace System.Web.Mvc
{
// Summary:
// Represents the properties and methods that are needed to render a view as
// a Web Forms page.
[FileLevelControlBuilder(typeof(ViewPageControlBuilder))]
public class ViewPage : Page, IViewDataContainer
{
<snip>
public object Model { get; }
Run Code Online (Sandbox Code Playgroud)
它怎么会选择错误的项目?
该项目创建为MVC4项目,然后在添加任何代码之前使用nuget升级到MVC5。
遗憾的是,ASP.NET MVC 5 的 Nuget 包似乎无法处理所需的 web.config 和代码更改以支持 ASP.NET MVC 5 中的所有内容。请查看http://www.asp。 net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2 应该有帮助您执行 Nuget 包未涵盖的所需手动升级步骤。