首先,在视图中,应该使用输入模型来接收从查询中传递的数据。在输入模型中定义所需的属性和属性的属性,如下所示:
public class InputModel
{
public string Name { get; set; }
public ChildModel Child { get; set; }
}
public class ChildModel
{
public int Age { get; set; }
public GrandchildModel Grandchild { get; set; }
}
public class GrandchildModel
{
public string Gender { get; set; }
}
然后,在控制器中,可以使用模型绑定将输入模型与查询字符串参数绑定:
public IActionResult Index(InputModel input)
{
string name = input.Name;
int age = input.Child.Age;
string gender = input.Child.Grandchild.Gender;
// ...
}
最后,在视图中,可以通过构建查询字符串将数据传递给控制器:
View Details