【发布时间】:2019-10-03 21:14:57
【问题描述】:
我不知道这是否是任何不同的默认配置,但是通过创建一个 asp.net core 2.2 项目和另一个 asp.net core 3.0 项目,我在模型绑定中得到了不同的结果。
public class Dto
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public string Prop3 { get; set; }
public string Prop4 { get; set; }
}
[HttpGet("test/{prop1:alpha}/{prop2:alpha}")]
public ActionResult<Result> Test(Dto dto)
{
}
上述代码在调用url时在asp.net core 2.2中完美运行:
https://localhost:xxxx/test/aaa/bbb/?prop3=ccc&prop4=ddd
但是,在 asp.net core 3 中,该对象为空。
如果我使用[FromRoute],它只会获取 prop1 和 prop2 的值。
如果我使用[FromQuery],它只会获取 prop3 和 prop4 的值。
如何配置 asp.net core 3 以便它像 asp.net core 2.2 一样获取路由和查询字符串的值?
请注意,在 asp.net core 2.2 中,我没有通知 [FromRoute] 或 [FromQuery],这在我看来是强制性的。
【问题讨论】:
标签: model-binding asp.net-core-3.0