gpt4 book ai didi

asp.net-mvc - ASP MVC - 使用参数模型中的列表调用 Controller

转载 作者:行者123 更新时间:2023-12-04 04:58:44 24 4
gpt4 key购买 nike

我想将 url 中的字符串数组传输到 mvc Controller 。

我的 Controller 方法是

public ActionResult Index(MyModel model)

我希望我的模型是
public class TagEditRequestVM
{
public string ValueA { get; set; }

public List<string> MyList { get; set; }
}

调用它的最佳 url 结构是什么?

最佳答案

您必须使用索引和 [] 符号:

http://host/Controller/Index?ValueA=val&MyList[0]=item1&MyList[1]=item2

索引不必是递增的整数 - 它必须是唯一的。

编辑

好的,感谢 plurby 在他的评论中写的链接,您可以省略括号符号,只需重复属性名称:
http://host/Controller/Index?ValueA=val&MyList=item1&MyList=item2

关于asp.net-mvc - ASP MVC - 使用参数模型中的列表调用 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16413717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com