1个回答
2013-09-13
展开全部
以MVC3为例向Controller传递个Dictionary(数组类似自己改吧)
Action:
public ActionResult PostDictionary(Dictionary<string, User> users)//user为一个用户类包含用户的基本信息
{
return View();
}
View:
@using (Html.BeginForm(" PostDictionary ", "Demo", FormMethod.Post)) //Action:PostDictionary;Controller: Demo
{
for (int i = 0; i < 3; i++)
{
<input type="hidden" name="users.index" value="@i" /> //告诉Controller有几个键值对
<table border="0">
<tbody>
<tr>
<td>
Key:
</td>
<td>
<input type="text" name="users[@i].key" />
</td>
</tr>
<tr>
<td>
User Name:
</td>
<td>
<input type="text" name="users[@i].value.UserName" />
</td>
</tr>
<tr>
<td>
Gender:
</td>
<td>
<select name="users[@i].value.Gender">
<option value="1">男</option>
<option value="2">女</option>
</select>
</td>
</tr>
</tbody>
</table>
<hr />
}
<input type="submit" value="Submit" />
}
Action:
public ActionResult PostDictionary(Dictionary<string, User> users)//user为一个用户类包含用户的基本信息
{
return View();
}
View:
@using (Html.BeginForm(" PostDictionary ", "Demo", FormMethod.Post)) //Action:PostDictionary;Controller: Demo
{
for (int i = 0; i < 3; i++)
{
<input type="hidden" name="users.index" value="@i" /> //告诉Controller有几个键值对
<table border="0">
<tbody>
<tr>
<td>
Key:
</td>
<td>
<input type="text" name="users[@i].key" />
</td>
</tr>
<tr>
<td>
User Name:
</td>
<td>
<input type="text" name="users[@i].value.UserName" />
</td>
</tr>
<tr>
<td>
Gender:
</td>
<td>
<select name="users[@i].value.Gender">
<option value="1">男</option>
<option value="2">女</option>
</select>
</td>
</tr>
</tbody>
</table>
<hr />
}
<input type="submit" value="Submit" />
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询