[英]How can I make Html.ListBoxFor required
我知道我可以通过添加必需的felid来使HTML页面中的DropDownListFor为必需:
@Html.DropDownListFor(m => m.Site_idSite, Model.GetSiteList(Model.idCompany), new { @class = "w_300p", required = "required" })
我的问题是如何使ListBoxFor为必需?
@Html.ListBoxFor(m => m.SelectedSites, Model.GetSiteList(Model.idCompany), new { @class = "w_250p", Size = "4" })
任何帮助将不胜感激。 长期困扰这个问题。
您可以尝试进行服务器端验证吗
public class ProgramViewModel
{
[Required(ErrorMessage = "Please select at least one company")]
public IEnumerable<string> YourCompanyIdList{ get; set; }
}
并且如果您想启用客户端验证,则可以使用以下参考: https : //www.codeproject.com/Articles/718004/ASP-NET-MVC-Client-Side-Validation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.