为什么我在ASP.NET MVC中收到“指令’控件’未知”错误?
我正在为ASP.NET MVC中的项目编辑页面.我想为创建页面和编辑页面使用一个控件,所以我不必重复代码.我在/ Views / Shared中设置了一个EditorTemplates文件夹来保存我的模板.我在那里放了一个名为ArticlePresentation.ascx的.ascx文件.
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> 我可以构建网站而不会出现任何错误,但是,当我运行网站并浏览到编辑页面时,我收到此错误:
我搜索谷歌寻找解决方案,但到目前为止我发现的一切都与在aspx页面而不是ascx页面中控制有关. 有谁知道可能导致此错误的原因是什么? 解决方法
您收到此错误的原因是您的文件具有.aspx扩展名而不是.ascx.仔细阅读错误消息:
现在将文件重命名为ArticlePresentation.ascx,一切都将按预期工作. 你也可以替换这一行: <%: Html.EditorFor(ArticlePresentation => ArticlePresentation)%> 有了这个: <%: Html.EditorForModel() %> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – ASP MVC用户配置文件
- ASP.NET MVC的客户端验证:jQuery的验证
- asp.net – 如何增加Web服务请求的超时?
- asp.net-mvc – 哪个更正确:使用UpdateModel()或接收模型作
- asp.net – 在内联.aspx页面中导入错误
- asp.net-mvc – 添加视图模型类下拉列表不显示我的类
- 如何做一个ASP.NET MVC Ajax表单与multipart/form-data?
- asp.net-core – 如何使用ASP.NET Core中的JWT授权重定向到
- asp.net – 读取文件属性有多贵? .净
- asp.net – 如何使用GridView和ObjectDataSource排序?
- 使用ASP.NET而不是MVC的Twitter引导程序
- asp.net-mvc – EF映射对象不兼容的数据读取器异
- ASP.NET MVC Core中launchSettings.json修改导致
- ASP.net页面上的表单标签
- asp.net-mvc – 使用ASP.NET MVC的Piranha CMS路
- asp.net – AspNetSynchronizationContext
- asp.net-mvc – Visual Studio断点未被击中
- asp.net-mvc – 如何成功配置Common.Logging?
- asp.net – 如何根据用户角色启用和禁用按钮?
- asp.net – 如何在MVC Razor中处理null子实体