【问题标题】:Abstract inherited member is not implemented未实现抽象继承成员
【发布时间】:2015-11-10 10:07:49
【问题描述】:

我在 Visual Studio 2013 中创建了一个新的 MVC 项目,在使用空模板(带模型)创建视图并使用布局页面(设置为空)后,我收到以下信息:

这会导致视图渲染不正确。我曾尝试在其他地方寻找解决方案,但无济于事。解决方案的清洁/重建也无济于事。令人讨厌的是,它是在一个全新的项目上这样做的。

关于如何解决的任何想法?

其他信息:

视图/Web.config

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="WebShopPortal.Web" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

下载视图模型

    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Web.Mvc;

    namespace WebShopPortal.Web.ViewModels
    {
        public class DownloadViewModel
        {
            public string ProductId { get; set; }

            public string DisplayText { get; set; }

            public string DownloadUrl { get; set; }

            public string OptionalReturnText { get; set; }

            [Required(ErrorMessage = "Title is required")]
            public string Title { get; set; }

            [DisplayName("First Name")]
            [Required(ErrorMessage = "First name is required")]
            public string FirstName { get; set; }

            [DisplayName("Last Name")]
            [Required(ErrorMessage = "Last name is required")]
            public string LastName { get; set; }

            [DisplayName("Job Title")]
            public string JobTitle { get; set; }

            [DisplayName("Company Name")]
            [Required(ErrorMessage = "Company name is required")]
            public string CompanyName { get; set; }

            [DisplayName("Company Type")]
            public int CompanyTypeId { get; set; }

            [DisplayName("Address Line 1")]
            public string Address1 { get; set; }

            [DisplayName("Address Line 2")]
            public string Address2 { get; set; }

            [DisplayName("Address Line 3")]
            public string Address3 { get; set; }

            [DisplayName("Address Line 4")]
            public string Address4 { get; set; }

            [DisplayName("City/Town")]
            public string Town { get; set; }

            [DisplayName("State/County")]
            public string County { get; set; }

            [DisplayName("Zip/Postcode")]
            public string Postcode { get; set; }

            public string Country { get; set; }

            [DisplayName("Phone Number")]
            public string WorkTelephone { get; set; }

            [DisplayName("Fax")]
            public string WorkFax { get; set; }

            [DisplayName("Email Address")]
            [EmailAddress(ErrorMessage = "Invalid Email Address")]
            [Required(ErrorMessage = "Email address is required")]
            public string EmailAddress { get; set; }

            public bool DoNotNotify { get; set; }

            public string ReturnUrl { get; set; }

            //Dropdowns
            public IEnumerable<SelectListItem> TitleList { get; set; }
            public IEnumerable<SelectListItem> CompanyTypeList { get; set; }
            public IEnumerable<SelectListItem> CountryList { get; set; } 
        }
    }

_ViewStart.cshtml

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

而且我可以向您保证,_Layout 页面中不会发生任何奇怪的事情。

更新

简单地关闭并重新打开解决方案似乎会使错误消失。

页面渲染也很好。奇怪的是,我在创建一个新项目后发生了这种情况。我会监控,看看以后是否会再次发生。

【问题讨论】:

  • 您是否将您的DownloadViewModel 标记为继承自WebPageBase? ViewModel 应该只代表 View 需要渲染的数据。
  • @haim770 我没有,它只是一个直截了当的 ViewModel。命名空间 WebShopPortal.Web.ViewModels { public class DownloadViewModel { public string ProductId { get;放; } } }
  • 然后显示您的~/Views/Web.Config 和任何相关的_ViewStart.cshtml 文件。
  • @Michael DownloadViewModel,我只是碰巧看到该名称是否导致错误。
  • 我可以在您的 View.config 文件中看到的唯一一件事是您缺少 节点和其中定义 pageBaseType 的 节点,对我来说,它的价值是 System .Web.Mvc.ViewPage.

标签: c# asp.net-mvc razor


【解决方案1】:

这是一个很长的镜头,但您可以尝试以下步骤:

  • 对溶液运行清洁
  • 卸载有问题的项目
  • 删除 Visual Studio 在
    旁边生成的 .user 文件 项目
  • 重新加载包含问题的项目
  • 构建解决方案

取自thread,或许可以帮到你。值得一试。

【讨论】:

  • 我会添加清除 asp 临时文件夹和 IIS express 网站文件夹
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多