私のインターフェイスには、次のようなテキストボックスのリストがあります: 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 />
<% }
%>
私のコントローラーで期待しているのは、最初のintがテンプレートIDで、もう1つがユーザーによって指定されたカウントであるIDictionaryを取得することです。
これが私が欲しいものです:
public ActionResult Save(int? id, Dictionary<int, int> countByTemplate)
私はたくさんのことを試しましたが、何もうまくいきませんでした。ソースを読み込もうとしましたが、迷路であり、モデルのバインドに関する情報を取得しようとすると頭が痛くなります。
質問:
- モデルバインディングがどのように機能するかについての優れたリソースはありますか?徹底的に説明したいのですが、特定の例について説明している84093043のブログにうんざりしています。
- IDictionary(またはコントローラーのアクションでIDictionary)を取得するために使用してHTMLを作成するにはどうすればよいですか?
あなたの助けをどうもありがとう