안녕하세요, 내 dropDownList에 html 속성 데이터 바인딩을 추가하려고합니다. 여기@ html.dropdownlist에 HtmlAttributes 추가
당신은 드롭 다운 내 코드를 볼 수 있습니다
DeviceDictionaryId는 아래와 같이 ViewBag를 통해 컨트롤러에서 보내는입니다@Html.DropDownList("DeviceDictionaryId" ,String.Empty)
:
var Ids = db.Dictionaries
.Select(s => new
{
DeviceDictionaryId = s.DeviceDictionaryId,
Description = s.DeviceManufacturer + " " + s.DeviceName
})
.ToList();
ViewBag.DeviceDictionaryId = new SelectList(Ids, "DeviceDictionaryId", "Description");
하지만 난 방법을 제대로 Htmlattribute을 추가하는 솔루션을 찾을 수 없습니다 . "= DeviceDictionaryId optionLabel = String.Empty로 htmlattributes = 새로운 {data_bind :
public static MvcHtmlString DropDownList(
string name,
IEnumerable<SelectListItem> selectList,
string optionLabel,
Object htmlAttributes
) 나를 위해
:
이름
나는 내가 사 개 인수를 제공 할 필요가 있음을 알고 값 : Id "}
하지만 무엇을 IEnumerable<SelectListItem> selectList,
으로 넣어야합니까?
1) 사용 jQuery를 아래처럼 속성을 추가 :이 오류를 무시하는 두 가지 방법을 발견
CS1973: 'System.Web.Mvc.HtmlHelper<dynamic>' has no applicable method named 'DropDownList' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
IEnumerable이므로,'Ids' 변수를 넣어야합니다 (제네릭 형식을'SelectListItem'으로 변경할 수 있습니다). 'DeviceDictionaryId'는'SelectList' 타입이므로 작동하지 않습니다. – Marthijn