C# 字段';xxx和x27;必须是MVC DropDownList中的数字

C# 字段';xxx和x27;必须是MVC DropDownList中的数字,c#,jquery,asp.net-mvc,asp.net-mvc-3,html-select,C#,Jquery,Asp.net Mvc,Asp.net Mvc 3,Html Select,我在MVC应用程序中使用DropDownList。加载页面时出现问题:DropDownList的HTML源代码中显示了一条错误消息 请看这张图片: 此字段已设置为允许数据库中的null,并且 using System.Web; using Nop.Web.Framework; using Nop.Web.Framework.Mvc; using Nop.Web.Validators.Customer; namespace Nop.Web.Models.Customer { public c

我在MVC应用程序中使用
DropDownList
。加载页面时出现问题:
DropDownList
的HTML源代码中显示了一条错误消息

请看这张图片:

此字段已设置为允许数据库中的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; }
 }
}
使用System.Web;
使用Nop.Web.Framework;
使用Nop.Web.Framework.Mvc;
使用Nop.Web.Validators.Customer;
命名空间Nop.Web.Models.Customer
{
公共类FileUploadModel:BaseNoEntityModel
{
公共CustomerNavigationModel导航模型{get;set;}
公共字符串ControlID{get;set;}
public int?EventID{get;set;}
公共IEnumerable事件{get;set;}
公共字符串扬声器文件{get;set;}
公共字符串文件{get;set;}
公共字符串logo文件{get;set;}
公共字符串PresentFile{get;set;}
公共字符串Present2File{get;set;}
公共字符串SpeakerFileUrl{get;set;}
公共字符串FirmFileUrl{get;set;}
公共字符串LogoFileUrl{get;set;}
公共字符串PresentFileUrl{get;set;}
公共字符串Present2FileUrl{get;set;}
公共字符串SpeakerSubmit{get;set;}
公共字符串FirmSubmit{get;set;}
公共字符串LogoSubmit{get;set;}
公共字符串PresentSubmit{get;set;}
公共字符串Present2Submit{get;set;}
}
}

在模型中

那些
数据-*
属性由不引人注目的验证框架添加。由于您的
EventID
属性被声明为整数,因此框架将验证ad添加这些属性的格式。它是可为空的整数,因此不需要添加
数据值
属性。

那些
数据-*
属性是由不引人注目的验证框架添加的。由于您的
EventID
属性被声明为整数,因此框架将验证ad添加这些属性的格式。它是可为空的整数,因此不需要添加
数据值
属性。

这有什么问题。当您在显示此消息的模型中定义int时。您已经将其定义为可空,若并没有,那个么还可能会有一条用于required的消息。“该字段是必需的。

这有什么问题。当您在显示此消息的模型中定义int时,您已经将其定义为可空,如果您没有定义,则可能还存在必需的消息。”该字段是必需的

您的下拉列表不应该绑定到事件而不是EventID吗

public int? EventID { get; set; }
public IEnumerable<System.Web.Mvc.SelectListItem> Events { get; set; }
公共int?EventID{get;set;} 公共IEnumerable事件{get;set;}
您的下拉列表不应该绑定到事件而不是EventID吗

public int? EventID { get; set; }
public IEnumerable<System.Web.Mvc.SelectListItem> Events { get; set; }
公共int?EventID{get;set;} 公共IEnumerable事件{get;set;}
在这种情况下,如何通过验证?验证是否将
下拉列表中的值作为
数字
?但验证应通过。只有在下拉列表中存在一些非整数的其他值时,这些属性才由非干扰性验证框架使用。但是从我看到的情况来看,您的下拉列表包含正确的整数值,因此不应向用户显示任何错误消息。因此,在这种情况下,如何使验证通过?验证是否将
下拉列表中的值作为
数字
?但验证应通过。只有在下拉列表中存在一些非整数的其他值时,这些属性才由非干扰性验证框架使用。但从我看到的情况来看,您的下拉列表包含正确的整数值,因此不应向用户显示任何错误消息。请不要在回答中使用粗体字母。我的模型中没有必需的属性。请不要在回答中使用粗体字母。我的模型中没有必需的属性。