This is a migrated thread and some comments may be shown as answers.

[Solved] Render dropdownlist from custom html extension

0 Answers 42 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Luis
Top achievements
Rank 1
Luis asked on 08 May 2012, 12:09 PM
Hello i'm trying to render an dropdownlist from a custom helper but i always get the following error.
'System.Web.Mvc.HtmlHelper<DataAcessModel.User>' does not contain a definition for 'CustomDropDown' and no extension method 'CustomDropDown' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<DataAcessModel.User>' could be found (are you missing a using directive or an assembly reference?) 

'System.Web.Mvc.HtmlHelper<DataAcessModel.User>' does not contain a definition for 'CustomDropDown' and no extension method 'CustomDropDown' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<DataAcessModel.User>' could be found (are you missing a using directive or an assembly reference?)

this is my code, can someone explain me how to complete this task.

public static void CustomDropDown(this HtmlHelper helper, DataAcessModel.User Model)
       {
           helper.Telerik().DropDownList().Name("Grid").Items(menu =>
           {
               Model.Delegacoes.ToList().ForEach(del =>
               {
                   menu.Add().Text(del.Name).Value(del.Id.ToString());
               });
           })
           .Render();
       }

just for you consideration i'm abble to access my class, because i'm rendering the following extension method.

public static MvcHtmlString BuildDropDownList(this HtmlHelper helper, IList<DataAcessModel.Delegacao> ilist)
{
    var context = helper.ViewContext;
 
    DataAcessModel.User user = (DataAcessModel.User)context.HttpContext.Session["user"];
 
    if (user != null)
        return new MvcHtmlString(string.Format("<div>{0}</div>", CreateMenu(user.Delegacoes)));
    else return null;
}

update:

i've tryied to access the the same extension but with a different overload, only whit the htmlHelper object and i get the same error!

public static void CustomDropDown2(this HtmlHelper helper)
        {
            helper.Telerik().DropDownList().Name("Grid").Items(menu =>
            {
                    menu.Add().Text("del.Name").Value("del.Id.ToString()");
            })
            .Render();
        }

Tags
ComboBox
Asked by
Luis
Top achievements
Rank 1
Share this question
or