0
votes

I'm trying to create a HTML helper for displaying a dropdown box in a certain way.

I've started to create one like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace uQuiz.WebUI
{
    public static class HtmlHelpers
    {

        public static  MvcHtmlString TimerMinuteSelectBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
        where TModel : class
        {
            // Error, no definition
            htmlHelper.DropDownBoxFor();
        }
    }
}

But htmlHelper doesn't contain a definition for DropDownBoxFor() or any other standard Html Helpers such as TextBoxFor()

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

I see that they are able to access it in this answer https://stackoverflow.com/a/16089427/894792 but I can't.

How can I get access to the standard HTML helpers in this answer.

1

1 Answers

1
votes

You need to add a reference to System.Web.Mvc.Html

public static  MvcHtmlString TimerMinuteSelectBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, ....
{
  MvcHtmlString dropdown = SelectExtensions.DropDownListFor(helper, expression, ....