ASP MVC -在参数模型中调用带有列表的控制器



我想把url中的字符串数组转移到mvc控制器。

我的控制器方法是
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

最新更新