在ASP.NET Core中从URL解析复杂结构可以使用Model Binding来实现。下面是一个包含代码示例的解决方法:
public class ComplexStructure
{
public string Property1 { get; set; }
public int Property2 { get; set; }
// 添加其他属性
}
[HttpGet]
public IActionResult MyMethod([FromQuery]ComplexStructure complexStructure)
{
// 执行方法逻辑
return Ok();
}
http://localhost:5000
,你可以使用以下URL来传递参数:http://localhost:5000/MyController/MyMethod?Property1=Value1&Property2=123
在上面的URL中,Property1
和Property2
分别对应复杂结构的属性。ASP.NET Core将自动解析URL中的参数,并将其赋值给复杂结构的属性。
这样,你就可以在ASP.NET Core中从URL解析复杂结构了。