虽然静态会出错

时间:2018-02-06 14:44:45

标签: asp.net-mvc html-helper mvchtmlstring

我正在写一个关于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);
}

所有静态方法..看起来类似的错误,但我不明白

错误:

  

DatepickerHelper.DatepickerFor(HtmlHelper,Expression&gt;,object,EInputAddonPosition?,EInputGroupSize?,EDateTimePickerFormat?,bool?,string)'必须声明一个正文,因为它没有标记为abstract,extern或partial

1 个答案:

答案 0 :(得分:1)

静态方法需要方法体。

你当前的实现确实什么都没做。

这会让您超过当前错误,但请注意throw new NotImplementedException(); - 您需要实际实施该方法,并返回适当的值。

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();
    }
}