我正在爲ASP.NET MVC中的項目編輯頁面。我想爲創建頁面和編輯頁面使用控件,所以我不必重複代碼。我在/Views/Shared
內設置了一個EditorTemplates
文件夾來保存我的模板。我在這裏放置了一個名爲ArticlePresentation.ascx
的.ascx文件。爲什麼我在ASP.NET MVC中得到「指令」控件「未知」錯誤?
ArticlePresentation.ascx
看起來是這樣的:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<genesis.Core.Presentation.ArticlePresentation>" %>
Testing the control
我Edit.aspx
看法是這樣的:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/genesis.Master" Inherits="System.Web.Mvc.ViewPage<genesis.Core.Presentation.ArticlePresentation>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Edit
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Edit</h2>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<%: Html.EditorFor(ArticlePresentation => ArticlePresentation)%>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
我可以建立該網站沒有得到任何錯誤,但是,當我運行的網站,瀏覽編輯頁面我得到這個錯誤:
System.Web.HttpParseException was unhandled by user code
Message=The directive 'control' is unknown. Source=System.Web ErrorCode=-2147467259 WebEventCode=0 FileName=C:<path to folder>asp.net mvc\genesis\genesis\Views\Shared\EditorTemplates\ArticlePresentation.aspx Line=2 VirtualPath=/Views/Shared/EditorTemplates/ArticlePresentation.aspx StackTrace: at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding) at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath) at System.Web.UI.TemplateParser.ParseInternal() at System.Web.UI.TemplateParser.Parse() at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType() at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider) at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
etc... etc...etc...
我查了谷歌正在尋找解決方案,但迄今爲止我發現的所有內容都涉及到在aspx頁面而不是ascx頁面中進行控制。
有誰知道什麼可能會導致此錯誤?
嘿達林 - 非常感謝您的幫助和提示。我注意到你以前幫過我一些很好的建議。當我使用解決方案資源管理器瀏覽到\ Views \ Shared \ EditorTemplates \時,我很困惑這個問題,因爲那裏唯一的文件叫做ArticlePresentation.ascx。我不明白爲什麼錯誤說這是一個aspx – quakkels 2010-06-25 18:13:47
有沒有辦法讓VWD 2010 Express重新評估該文件夾中的文件? – quakkels 2010-06-25 18:15:49
感謝那些注意細節達林。顯然,我有2個文件(一個aspx和一個ascx),但解決方案資源管理器只顯示ascx。我使用Windows資源管理器刪除了aspx,並再次構建了該項目。中提琴!它嚇人。謝謝 – quakkels 2010-06-25 18:35:27