[英]The field 'xxx' must be a number in MVC DropDownList
我在我的MVC应用程序中使用DropDownList
。 加载页面时出现问题: DropDownList
的HTML源中显示了一条错误消息。
请看这张图片:
此字段已设置为允许DB中为null,并且
using System.Web;
using Nop.Web.Framework;
using Nop.Web.Framework.Mvc;
using Nop.Web.Validators.Customer;
namespace Nop.Web.Models.Customer
{
public class FileUploadModel : BaseNopEntityModel
{
public CustomerNavigationModel NavigationModel { get; set; }
public string ControlID { get; set; }
public int? EventID { get; set; }
public IEnumerable<System.Web.Mvc.SelectListItem> Events { get; set; }
public string SpeakerFile { get; set; }
public string FirmFile { get; set; }
public string LogoFile { get; set; }
public string PresentFile { get; set; }
public string Present2File { get; set; }
public string SpeakerFileUrl { get; set; }
public string FirmFileUrl { get; set; }
public string LogoFileUrl { get; set; }
public string PresentFileUrl { get; set; }
public string Present2FileUrl { get; set; }
public string SpeakerSubmit { get; set; }
public string FirmSubmit { get; set; }
public string LogoSubmit { get; set; }
public string PresentSubmit { get; set; }
public string Present2Submit { get; set; }
}
}
在模型中。
您的DropDown列表不应该绑定到事件,而不是绑定到EventID吗?
public int? EventID { get; set; }
public IEnumerable<System.Web.Mvc.SelectListItem> Events { get; set; }
那些data-*
属性是由非侵入式验证框架添加的。 由于您的EventID
属性声明为整数,因此框架会验证广告添加这些属性的格式。 它是可为空的整数,因此没有添加data-val-required
属性。
这是什么问题。 当您在模型中定义int时,它会显示此消息。 并且您已经将其定义为可为空,如果没有,则可能还会有要求提供的消息。 “该字段为必填项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.