Search code examples
asp.net-mvchtml-helpermvchtmlstring

Although static gives an error


I'm writing a helper about datetime.

public static class DatepickerHelper
{
    public static MvcHtmlString Datepicker(this HtmlHelper htmlHelper, string name, object value = null, object htmlAttributes = null, EInputAddonPosition? addonPosition = EInputAddonPosition.Right, EInputGroupSize? groupSize = EInputGroupSize.Medium, EDateTimePickerFormat? Format = EDateTimePickerFormat.GunAyYil, bool? showRemoveButton = false, string onChangeFn = "");

    public static MvcHtmlString DatepickerFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes = null, EInputAddonPosition? addonPosition = EInputAddonPosition.Right, EInputGroupSize? groupSize = EInputGroupSize.Medium, EDateTimePickerFormat? Format = EDateTimePickerFormat.GunAyYil, bool? showRemoveButton = false, string onChangeFn = "");

    public static string GetStringValue(Enum value);
}

all static methods .. looked similar errors but I do not understand

Error:

DatepickerHelper.DatepickerFor(HtmlHelper, Expression>, object, EInputAddonPosition?, EInputGroupSize?, EDateTimePickerFormat?, bool?, string)' must declare a body because it is not marked abstract, extern, or partial


Solution

  • Static methods require a method body.

    Your current implementation literally does nothing.

    This will get you past your current error, but please note the throw new NotImplementedException(); - you'll need to actually implement the method, and return an appropriate value.

    public static class DatepickerHelper
    {
        public static MvcHtmlString Datepicker(this HtmlHelper htmlHelper, string name, object value = null, object htmlAttributes = null, EInputAddonPosition? addonPosition = EInputAddonPosition.Right, EInputGroupSize? groupSize = EInputGroupSize.Medium, EDateTimePickerFormat? Format = EDateTimePickerFormat.GunAyYil, bool? showRemoveButton = false, string onChangeFn = "")
        {
            //notice there's a body to this static method now
            throw new NotImplementedException();
        }
    
    
        public static MvcHtmlString DatepickerFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes = null, EInputAddonPosition? addonPosition = EInputAddonPosition.Right, EInputGroupSize? groupSize = EInputGroupSize.Medium, EDateTimePickerFormat? Format = EDateTimePickerFormat.GunAyYil, bool? showRemoveButton = false, string onChangeFn = "")
        {
            //notice there's a body to this static method now
            throw new NotImplementedException();
        }
    
        public static string GetStringValue(Enum value)
        {
            //notice there's a body to this static method now
            throw new NotImplementedException();
        }
    }