Why am I getting the "Pointing" error "unknown" in ASP.NET MVC?

I am working on an editor page for a project in ASP.NET MVC. I would like to use the control for both the create page and the edit page, so I don't need to duplicate the code. I created the EditorTemplates folder inside /Views/Shared to store my templates. And I put there an .ascx file called ArticlePresentation.ascx .

ArticlePresentation.ascx as follows:

 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<genesis.Core.Presentation.ArticlePresentation>" %> Testing the control 

My Edit.aspx view is as follows:

 <%@ 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> 

I can create a site without any errors, but when I start the site and go to the edit page, I get this error:

System.Web.HttpParseException failed to process 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....

I searched google to find solutions, but all I have found so far is that the control is on the aspx page, not the ascx page.

Does anyone know what might cause this error?

+4
source share
1 answer

The reason you get this error is because your file has the extension .aspx , not .ascx . Read the error message carefully:

ErrorCode = -2147467259

WebEventCode = 0

FileName = C: \ Documents and Settings \ bquakkelaar \ Desktop \ DropStuff \ asp.net MVC \ genesis \ genesis \ Views \ Shared \ EditorTemplates \ ArticlePresentation. Aspx

Now rename the file to ArticlePresentation.ascx and everything will work as expected.

You can also replace this line:

 <%: Html.EditorFor(ArticlePresentation => ArticlePresentation)%> 

with this:

 <%: Html.EditorForModel() %> 
+4
source

Source: https://habr.com/ru/post/1313896/


All Articles