我在 Visual Studio 2013 中创建了一个新的 MVC 项目,在使用空模板(带模型)创建 View 并使用布局页面(设置为空)后,我收到以下信息:
这会导致 View 呈现不正确。我曾尝试在其他地方寻找解决方案,但无济于事。清洁/重建解决方案也无济于事。令人恼火的是它在一个全新的项目上这样做。
关于如何修复的任何想法?
附加信息:
View /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>
下载 View 模型
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 页面中没有发生任何奇怪的事情。
更新
简单地关闭并重新打开解决方案似乎可以使错误消失。
页面也呈现良好。在创建一个新项目后,这发生在我身上很奇怪。我会监控,看看将来是否会再次发生。
最佳答案
希望不大,但您可以尝试以下步骤:
- 对解决方案进行清理
- 卸载有问题的项目
- 删除 Visual Studio 在
旁边生成的 .user 文件 项目 - 重新加载有问题的项目
- 构建解决方案
取自此thread ,也许可以帮助你。值得一试。
关于c# - 抽象继承成员未实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33627473/