MultiSelectList
의 dataValueField는 코드 숨김 모델의 숫자이고 dataTextField 필드는 string입니다.숫자 ID 값에 대한 MultiSelectList 유효성 검사
결과 html select
요소에서 여러 값을 선택하면 유효성 검사 오류가 발생하여 must be a number
필드가 표시됩니다. 이것은 뒷받침 필드가 정수이기 때문에 의미가 있으며 여러 항목을 선택하면 건물의 id 값이 쉼표를 사용하여 연결됩니다. 이 문제를 해결할 수있는 방법은 무엇입니까? 감사.
모델은 다음과 같습니다.
// Selected buildings are stored in this table.
public class ClientSelectedBuildings
{
public int ClientSelectedBuildingsId { get; set; }
// ...
[Display(Name = "Please select the buildings under consideration.")]
public int? BuildingId { get; set; }
}
// Building list is retrieved from this table.
public class Buildings
{
public int BuildingsId { get; set; }
// ...
[StringLength(255)]
public string BuildingName { get; set; }
}
내보기는 다음과 같습니다.
@model TheApplication.Models.ClientSelectedBuildings
<div class="outer">
<div class="inner">
@Html.LabelFor(t => t.BuildingId)
@Html.ListBoxFor(t => t.BuildingId, (MultiSelectList)ViewBag.Buildings, new { size = "4" })
@Html.ValidationMessageFor(t => t.BuildingId)
</div>
</div>
위대한 답변 주셔서 감사합니다! – erdinger