Asp.net mvc 当我将int设置为空字符串时,FluentValidation通过NotEmpty()传递空字符串

Asp.net mvc 当我将int设置为空字符串时,FluentValidation通过NotEmpty()传递空字符串,asp.net-mvc,asp.net-mvc-5,fluentvalidation,Asp.net Mvc,Asp.net Mvc 5,Fluentvalidation,我有这个验证码 RuleFor(x => x.Name).NotEmpty().WithMessage("[[[Name is required.]]]"); const string sortWeightError = "[[[Sort weight must be a value between 1 and 10000.]]]"; RuleFor(x => x.SortWeight).NotEmpty().WithMessage(s

我有这个验证码

        RuleFor(x => x.Name).NotEmpty().WithMessage("[[[Name is required.]]]");
        const string sortWeightError = "[[[Sort weight must be a value between 1 and 10000.]]]";
        RuleFor(x => x.SortWeight).NotEmpty().WithMessage(sortWeightError);
其中Name是一个
字符串
,SortWeight是一个
int
。 当我将SortWeight设置为0并将name设置为空字符串进行验证时,这两个选项都会像应该的那样失败

但是,只要我还将SortWeight清除为空字符串(之前为0),那么Name(yes Name,而不是SortWeight)通过验证,即使它仍然是空字符串

如果我将SortWeight设置为int?它不是int,而是按预期工作,只是它允许0,我用GreaterThan修复了0


但是,非常奇怪的行为,文档说它应该确保不管是哪种类型的字符串都不是null或空/空白字符串。最奇怪的是,当我传入一个空字符串时,它仍然没有通过SortWeight字段,但它随后传递了另一个字段(名称),该字段本应始终失败,因为它总是有一个空字符串。

刚刚尝试在nuget中更新fluentvalidation,仍然没有成功。有些不清楚-您说“SortWeight to a empty string”当它是一个int或int?,但这在C#中是不可能的。也许您可以发布一个意外失败的完整代码块?我指的是浏览器中的空字段。