MVC actionlink 发布复杂类型列表
我有一个操作链接,单击该链接即可将对象列表传递给控制器操作。
示例:
View:
Html.ActionLink("TestLink", "TestMethod", "Test", Model.SampleList, null)
TestController:
public ActionResult TestMethod(List<SampleList> sampleList)
{
return View(sampleList);
}
当我这样做时,我得到一个空的样本列表。我可以传递一个复杂的对象,但不能传递它的集合。我需要正确的路由吗?我这样做的原因是不是传递 id 并在控制器操作中进行查找,而是只是传递数据。
I have an actionlink that on click im passing a List of objects to a controller action.
Example:
View:
Html.ActionLink("TestLink", "TestMethod", "Test", Model.SampleList, null)
TestController:
public ActionResult TestMethod(List<SampleList> sampleList)
{
return View(sampleList);
}
When I do this I get a null sampleList. I can pass a single complex object fine just not a collection of it. Do I need the correct routing for this? The reason I'm doing this is instead of passing an id and do a look up in the controller action, I just pass in the data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您执行表单发布时,可以查看 此博客文章了解更多信息。不过,您可能无法使用 HtmlHelper 方法之一,该帖子指出:
不过,没有什么可以阻止您编写自己的助手。
It is possible when you perform a form post, have a look at this blog post for more information. You'll probably not be able to use one of the HtmlHelper methods though, the post states:
Nothing prevents you from writing your own helper though.