我有一个MultiSelectList
其 dataValueField 是代码隐藏模型中的数字,而 dataTextField 字段是字符串。
当我在生成的 htmlselect
元素中选择多个值时,我收到验证错误,指出该字段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>