ASP.NET MVC局部视图使用表单 [英] ASP.NET MVC Partial View with Form

查看:169
本文介绍了ASP.NET MVC局部视图使用表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景我想用一个局部视图,但我有它的数据传递给控制器​​的问题。这里是什么我试图做一个基本的例子。

I have a scenario I want to use a partial view but I'm having issues with it passing data to the controller. Here is a basic example of what I'm trying to do.

对象:


  • 客户

  • 订单

一个客户有一个的IList<排序> 就可以了。我想的局部视图,以允许用户编辑的信息。我可以得到的数据显示,但是当表单发送客户对象下的列表为空。

A Customer has an IList<Order> on it. I want the partial view to allow the user to edit the information. I can get the data to display but when the form posts the list under the Customer object is null.

我也试图在我的局部视图使用一个单独的形式。当我这样做,如果我在控制器上创建paramenters像这样我得到的数据:

I have also attempted to use a seperate form in my partial view. When I do this if I create paramenters on the controller like so I get the data:

public ActionResult UpdateOrders(IList<Guid> id, IList<int> quantity, IList<Guid> productId)

但是,当我做到这一点。

But when I do this

public ActionResult UpdateOrders(IList<Order> orders)

该列表为空。

如果任何人有如何实现这一点让我知道一个更好的建议。

If anyone has a better suggestion of how to achieve this let me know.

推荐答案

你是如何引用视图中的字段?我想,这应该是这样的:

How are you referencing the fields in your view? I'm thinking that it should be something like:

<input type="hidden" name="orders.Index" value="0" />
<input type="hidden" name="oders[0].ID" value="1" />
<input type="hidden" name="orders[0].productId" value="4" />
<input type="text" name="orders[0].quantity" value="6" />

<input type="hidden" name="orders.Index" value="1" />
<input type="hidden" name="orders[1].ID" value="2" />
<input type="hidden" name="orders[1].productId" value="2" />
<input type="text" name="orders[1].quantity" value="15" />

查看结合一个列表获取更多信息。

这篇关于ASP.NET MVC局部视图使用表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆