3

I have a perfectly working ascx editor template in ASP.NET MVC 3, and tried to convert it to 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"))
%>

Razor:

@inherits  System.Web.Mvc.ViewUserControl<Inventory.Models.ProductCategory>

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

I renamed the ascx so it wouldn't clash when ASP.NET is picking the editor template, I saved the razor file with a cshtml extension, all that. But in runtime, I get this error:

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");

What am I doing wrong? Aren't Razor EditorTemplates recognized by ASP.NET MVC?

2 Answers 2

12

Razor views cannot inherit from ViewUserControl. Instead you want to just specify the model of your Razor view:

@model Inventory.Models.ProductCategory

@(Html.Telerik().DropDownList()
      .Name("ProductCategory")
      .BindTo(new SelectList((IEnumerable)ViewData["ProductCategories"], "Id", "Name"))   ) 
Sign up to request clarification or add additional context in comments.

2 Comments

D'oh! I completely missed that :| Thanks! :)
Yeah me two.. Just spent an hour fighting with it. Big D'oh! Thank you very much ;)
0

Make sure you are not an old version of the Telerik controls which might not be compiled against ASP.NET MVC 3.0 (System.Web.Mvc 3.0 assembly). Also make sure you have followed the instructions described in the documentation for the prerequisite steps.

1 Comment

I have the latest version of Telerik released couple of days back. It supports the Razor syntax. Also, your code and mine are functionally same, and don't work when tried :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.