Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Nancy模型绑定所需的属性验证不起作用_C#_.net_Model Binding_Nancy_Requiredfieldvalidator - Fatal编程技术网

C# Nancy模型绑定所需的属性验证不起作用

C# Nancy模型绑定所需的属性验证不起作用,c#,.net,model-binding,nancy,requiredfieldvalidator,C#,.net,Model Binding,Nancy,Requiredfieldvalidator,我正在通过路由url使用NancyFx模型绑定,并尝试为所需属性设置一些验证。课程安排如下: public class Query { [Required] public string ClientId { get; set; } public List<string> Customers { get; set; } } Get["/test?customers=c1,c2"] = args => { var q

我正在通过路由url使用NancyFx模型绑定,并尝试为所需属性设置一些验证。课程安排如下:

public class Query
{
    [Required]
    public string ClientId { get; set; }
    public List<string> Customers { get; set; }
}
Get["/test?customers=c1,c2"] = args =>
        {
            var query = new Query(); // A

            try
            {
                query = this.Bind<Query>(); // B
            }
            catch (ModelBindingException ex)
            {
                throw ex;
            }

            return db.Execute(Query);
        };
    }
公共类查询
{
[必需]
公共字符串ClientId{get;set;}
公共列表客户{get;set;}
}
我的路线如下:

public class Query
{
    [Required]
    public string ClientId { get; set; }
    public List<string> Customers { get; set; }
}
Get["/test?customers=c1,c2"] = args =>
        {
            var query = new Query(); // A

            try
            {
                query = this.Bind<Query>(); // B
            }
            catch (ModelBindingException ex)
            {
                throw ex;
            }

            return db.Execute(Query);
        };
    }
Get[“/test?customers=c1,c2”]=args=>
{
var query=new query();//A
尝试
{
query=this.Bind();//B
}
捕获(ModelBindingException-ex)
{
掷骰子;
}
返回db.Execute(查询);
};
}
首先,我希望会出现某种异常,因为ClientId是必需的,但在初始化新查询时它为null,但没有任何异常

如果做不到这一点,在B,我希望在尝试绑定查询对象时会出现某种错误。查看调试器,查询对象的Customers属性正确地具有预期值“c1,c2”。但是,查询对象中的ClientId为null,并且没有错误。我想知道我能做些什么来触发一个基于ClientId是必需的事实的异常。

检查