모든 내장 HtmlHelper
메소드는 HTML 속성을 추가 할 수 과부하가 있습니다.
ListBoxFor()
방법의 경우, overloads are documented here. 하이픈을 포함하는 속성을 추가 할 때 귀하의 경우에는 그
@Html.ListBoxFor(m => m.someProperty, Model.Options, new { data_someName = "someValue" })
하는
<select name="someProperty" id="someProperty" multiple="multiple" data-someName="someValue"> .... </select>
주를 생성합니다, 당신은 방법에 밑줄을 사용해야합니다 (및 방법은 렌더링에 하이픈으로 변환됩니다 html).
또한 예를 들어 자동
public static MvcHtmlString BootstrapTextBoxFor<TModel, TValue>(this HtmlHelper<TModel> helper,
Expression<Func<TModel, TValue>> expression, object htmlAttributes)
{
IDictionary<string, object> attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
attributes.Add("class", "form-control");
... other 'fixed' attributes as required
return InputExtensions.TextBoxFor(helper, expression, attributes);
}
몇 가지 다른 예는됩니다 class="form-control"
속성을 추가하는 BootstrapTextBoxFor()
도우미를 만들 수 있습니다, 자동으로 추가 고정 속성을 포함한보다 복잡한 HTML을 생성 할 수 있습니다 자신의 HtmlHelper
확장 메서드를 만들 수 있습니다 대답 here 및 here에 나와 있습니다.
예 내장 된'ListBoxFor()'메소드를 호출하고'htmlAttributes' 매개 변수에 추가 값을 추가하는 자신 만의'MyListBoxFor()'메소드를 만들 수 있습니다 –
C#이나 mvc 아직, 정확히 무슨 뜻인지 샘플을 작성 하시겠습니까? – blubberbo
왜 이렇게해야하는지 명확하지 않습니다. @Html.ListBoxFor (m => m.someProperty, Model.Options, new {data_someName = "someValue"}) ' –