我在 ASP.NET MVC 3 中有一个完美运行的 ascx 编辑器模板,并尝试将其转换为 razor:
Ascx:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Inventory.Models.ProductCategory>" %>
<%= Html.Telerik().DropDownList()
.Name("ProductCategory")
.BindTo(new SelectList((IEnumerable)ViewData["ProductCategories"], "Id", "Name"))
%>
剃刀:
@inherits System.Web.Mvc.ViewUserControl<Inventory.Models.ProductCategory>
@(Html.Telerik().DropDownList()
.Name("ProductCategory")
.BindTo(new SelectList((IEnumerable)ViewData["ProductCategories"], "Id", "Name"))
)
我重命名了 ascx,这样当 ASP.NET 选择编辑器模板时它不会发生冲突,我保存了带有 cshtml 扩展名的 razor 文件,所有这些。但在运行时,我收到此错误:
CS0115: 'ASP._Page_Views_Shared_EditorTemplates_ProductCategory_cshtml.Execute()': no suitable method found to override
Line 44: }
Line 45:
Line 46: public override void Execute() {
Line 47:
Line 48: WriteLiteral("\r\n");
我究竟做错了什么?ASP.NET MVC 不识别 Razor EditorTemplates 吗?