在我的界面中,我有一个文本框列表,如下所示: http ://screencast.com/t/YjIxNjUyNmU
文本框的数量是未知的,因为它们中的每一个都与一个模板相关联。在我的页面中,目标是将数字与其中一些模板相关联。
这是一个示例 HTML 代码:
<% // loop on the templates
foreach(ITemplate template in templates)
{
// get the content from the input dictionary
int val;
content.TryGetValue(template.Id, out val);
// convert it as a string
string value = ((val > 0) ? val.ToString() : string.Empty);
// compute the element name/id (for dictionary binding)
string id = ??????????
string name = ??????????????
%>
<label for="<%= name %>"><%= template.Name %></label>
<input type="text" id="<%= id %>" name="<%= name %>" value="<%= value %>" />
<br />
<% }
%>
在我的控制器中,我期望得到一个 IDictionary,其中第一个 int 是模板 ID ,另一个是用户给出的计数。
这是我想要的:
public ActionResult Save(int? id, Dictionary<int, int> countByTemplate)
我尝试了很多东西,但没有任何效果。我试图阅读源代码,但它是一个迷宫,我正在头疼试图获取有关模型绑定的信息。
问题 :
- 是否有关于模型绑定如何工作的良好资源?我想要一些详尽的内容,我厌倦了讨论给定特定示例的 84093043 博客。
- 如何构建我的 HTML,用于获取 IDictionary(甚至是控制器操作中的 IDictionary?
非常感谢你的帮助