【问题标题】:Error creating EditorTemplates in Razor在 Razor 中创建 EditorTemplates 时出错
【发布时间】:2011-06-14 14:26:44
【问题描述】:

我在 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 吗?

【问题讨论】:

    标签: asp.net-mvc telerik asp.net-mvc-3 razor editortemplates


    【解决方案1】:

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

    【讨论】:

    • 我在几天前发布了最新版本的 Telerik。它支持 Razor 语法。此外,您的代码和我的代码在功能上是相同的,并且在尝试时不起作用:(
    【解决方案2】:

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

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

    【讨论】:

    • 天啊!我完全错过了:|谢谢! :)
    • 是的,我两个.. 只花了一个小时与它战斗。大德哦!非常感谢;)
    猜你喜欢
    • 2012-05-14
    • 1970-01-01
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 2015-05-28
    • 2015-07-03
    • 2020-10-20
    相关资源
    最近更新 更多