首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Razor中创建EditorTemplates时出错

在Razor中创建EditorTemplates时出错
EN

Stack Overflow用户
提问于 2011-01-24 23:32:01
回答 2查看 4.1K关注 0票数 2

我在ASP.NET MVC3中有一个完美工作的ascx编辑器模板,并尝试将其转换为razor:

Ascx:

代码语言:javascript
复制
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Inventory.Models.ProductCategory>" %>

<%= Html.Telerik().DropDownList()
    .Name("ProductCategory")
        .BindTo(new SelectList((IEnumerable)ViewData["ProductCategories"], "Id", "Name"))
%>

剃刀:

代码语言:javascript
复制
@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扩展名保存了剃刀文件,诸如此类。但是在运行时,我得到了这个错误:

代码语言:javascript
复制
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吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-01-25 02:55:08

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

代码语言:javascript
复制
@model Inventory.Models.ProductCategory

@(Html.Telerik().DropDownList()
      .Name("ProductCategory")
      .BindTo(new SelectList((IEnumerable)ViewData["ProductCategories"], "Id", "Name"))   ) 
票数 12
EN

Stack Overflow用户

发布于 2011-01-24 23:35:47

确保您不是针对ASP.NET MVC3.0( Telerik 3.0程序集)编译的Telerik控件的旧版本。另外,请确保您已经按照instructions described in the documentation中的前提步骤进行了操作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4783764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档