我正在通过创建一个新的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>我得到错误'object‘不包含'Title’的定义,也没有扩展方法.
关于模型的定义让我来到这里:
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; }为什么它选错了项目?
该项目是作为一个MVC4项目创建的,然后在添加任何代码之前使用nuget升级到MVC5。
发布于 2013-10-28 01:23:46
遗憾的是,针对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包没有涵盖的所需的手动升级步骤。
发布于 2017-05-17 20:18:18
对我来说,由于默认配置假设是剃刀,所以我在我的View/web.config中忽略了这一点。
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<pages pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc,
Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc,
Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc,
Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
>
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
</namespaces>
</pages>
</system.web>https://stackoverflow.com/questions/19610928
复制相似问题