2011-01-24 107 views
2

创建EditorTemplates我在ASP.NET MVC 3完美的工作ASCX编辑模板,并试图将其转换为剃刀:错误剃刀

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 EditorTemplates吗?

回答

12

剃刀视图不能从ViewUserControl继承。 相反,你只想指定Razor视图模型:

@model Inventory.Models.ProductCategory 

@(Html.Telerik().DropDownList() 
     .Name("ProductCategory") 
     .BindTo(new SelectList((IEnumerable)ViewData["ProductCategories"], "Id", "Name")) ) 
+0

D'oh!我完全错过了:|谢谢!:) – 2011-01-25 06:34:48

0

确保您不是Telerik控件的旧版本,它可能不会针对ASP.NET MVC 3.0(System.Web.Mvc 3.0程序集)进行编译。还请确保您已按照instructions described in the documentation的先决步骤操作。

+0

我Telerik的最新版本发布几天回来。它支持Razor语法。此外,你的代码和我的功能是一样的,并且在尝试时不工作:( – 2011-01-24 15:39:20