2013-08-06 8 views
-1

이 함수는 어떻게 호출합니까? (면도기 구문을 사용하여) 페이지 내부다음 함수는 어떻게 호출합니까?

public static HtmlString DropdownForEnum<TModel>(this HtmlHelper<TModel> helper, Type type, 
    string name, string optionLabel, object htmlAttributes) 
+1

유용한 설명 유용한 답변 – bman

답변

5

는 :

@Html.DropDownForEnum(typeof(enumToDropDown), name: "Foo", optionLable: "Bar", htmlAttributes: null) 
+0

부끄러움없이 직접 답변 해 주셔서 감사합니다. – bman

1

이 Html 헬퍼의 확장 방법. 는 그래서, 그것은 다음과 같이 호출해야합니다 : tModel을이 선언의 순간에 일반에 할당 된 유형입니다

HtmlHelper<TModel> instance = new HtmlHelper<TModel>(); 
instance.DropdownForEnum(type, name, optionLabel, htmlAttributes) 

.

이 질문을 참조하십시오 : 확장 방법에 대한 MVC3 Razor DropDownListFor Enums

을이를 참조하십시오 는 http://msdn.microsoft.com/en-us/library/vstudio/bb383977.aspx

1

Html 헬퍼extension 방법이다. 그것에 대해 자세히 알 수 있습니다 here.

당신은이

yourhtmlHelperObject.DropdownForEnum(someType,someName,label,attributes); 
2

다음은 인수 "이"부분은 그는 "확장 메서드"의 나에게 나타냅니다 LKE 호출 할 수 있습니다 - 기본적으로 도우미 메서드 개체에 대한 일부 공공 작업을 수행하지만, 마치 그 객체의 메소드 인 것처럼 호출 될 수 있습니다.

HtmlHelper<Model> helper; 
Type type; 
String name; 
String optionLabel; 
Object htmlAttributes; 

helper.DropdownForEnum(type, name, optionLabel, htmlAttributes); 
// or, the standard way for calling a static: 
NameOfClassWhereYouFoundMethod.DropdownForEnum(helper, type, name, optionLabel, htmlAttributes); 
+0

을 제외하고는 함수에 정적 선언이 있으므로 HtmlHelper의 인스턴스에서 호출되지 않습니다. –

+0

@MikeCorcoran HtmlHelper의 인스턴스가 인수로 지정되므로 모든 확장 메서드가 정적으로 선언됩니다. (이 HtmlHelper ...) – Katana314

+0

우, brainfart. 당신 말이 맞아, 나는 바깥 쪽 클래스 선언 만 정적이어야한다고 생각하고 있었어. –

관련 문제