Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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# ASP MVC创建参数模型,即使没有任何参数';不提供_C#_Asp.net_Asp.net Mvc_Rest - Fatal编程技术网

C# ASP MVC创建参数模型,即使没有任何参数';不提供

C# ASP MVC创建参数模型,即使没有任何参数';不提供,c#,asp.net,asp.net-mvc,rest,C#,Asp.net,Asp.net Mvc,Rest,我正在用ASP.Net MVC创建一个RESTful API 有问题的一个得到路线。我创建了一个参数模型来处理所有接收参数 public class MyParameters : BaseParameters { public string ProductCode { get; set; } ... } 以这种方式使用这个类: public HttpResponseMessage Get([FromUri] MyParameters filter) 问题是当我没有

我正在用ASP.Net MVC创建一个RESTful API
有问题的一个得到路线。我创建了一个参数模型来处理所有接收参数

 public class MyParameters : BaseParameters
 {
    public string ProductCode { get; set; }
    ...
 }
以这种方式使用这个类:

 public HttpResponseMessage Get([FromUri] MyParameters filter)  
问题是当我没有传递任何参数时-过滤器对象没有初始化。它始终为空。
但无论如何我都需要初始化这个对象,因为有一些默认参数,比如标志,我在构造函数中初始化它们

 public MyParameters()
    {
        AuthFlag = 'Y';
    }
我知道这是默认行为,但我不想这样做:

if (filter == null)
      filter = new MyParameters();
是否有任何配置可用于创建参数对象


谢谢你的建议

有空传播操作符:

filter = filter ?? new MyParameters();

或者,您可以实现自己的模型绑定器/模型绑定器提供程序。作为起点,您可以引用。

有空传播运算符:

filter = filter ?? new MyParameters();
或者,您可以实现自己的模型绑定器/模型绑定器提供程序。作为起点,您可以参考