小编Yan*_*net的帖子

可选参数始终填充

我在控制器中有一个方法:

public ActionResult SendNotification(Guid? id=null, SendNotification notification =null)
Run Code Online (Sandbox Code Playgroud)

它响应 /Apps/SendNotification/{guid}?{SendNotification properties}

SendNotification是具有多个字符串属性的模型.

我的问题是SendNotification永远不会为空.无论我如何调用该操作,.NET似乎总是实例化SendNotification的对象(所有字段都为null).

我甚至与测试System.Web.Http.FromUri,并System.Web.Http.FromBody和它仍然做到这一点.

有任何想法吗?

注意:这不是WebApi.这是常规的MVC.

我的项目只有默认路由:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

6
推荐指数
1
解决办法
178
查看次数

标签 统计

asp.net-mvc ×1

c# ×1