我在ASP.NET MVC3中有一个完美工作的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扩展名保存了剃刀文件,诸如此类。但是在运行时,我得到了这个错误:
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吗?
发布于 2011-01-25 02:55:08
剃刀视图不能从ViewUserControl继承。相反,您只需要指定Razor视图的模型:
@model Inventory.Models.ProductCategory
@(Html.Telerik().DropDownList()
.Name("ProductCategory")
.BindTo(new SelectList((IEnumerable)ViewData["ProductCategories"], "Id", "Name")) ) 发布于 2011-01-24 23:35:47
确保您不是针对ASP.NET MVC3.0( Telerik 3.0程序集)编译的Telerik控件的旧版本。另外,请确保您已经按照instructions described in the documentation中的前提步骤进行了操作。
https://stackoverflow.com/questions/4783764
复制相似问题