Okay, I'm not trying to do anything super complex, I have searched, and searched, and roamed every blog and forum I can find. I am about to tear my hair out because no one just outright shows it working.
I want to use an IDictionary in my Model. Nevermind the reason why, that's irrelevant. I just want to do something very simple, and understand what is going on.
Can someone please help me figure out the HTML I should be putting in the View to make this work right? Please? I have tried Html.TextBoxFor and it comes back null on the postback. I have tried manually using the index of the dictionary item, and it comes back null. I am really getting frustrated, and all I keep seeing is redirection to blogs that don't answer the question.
Controller
public ActionResult DictionaryView()
{
var model = new Dictionary<string, int>
{
{ "First", 0 },
{ "Second", 0 },
{ "Third", 0 },
{ "Fourth", 0 }
};
return View(model);
}
[HttpPost]
public ActionResult DictionaryView(Dictionary<string, int> dictionary)
{
return null;
}
HTML
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<System.Collections.Generic.IDictionary<string,int>>" %>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<h2>Dictionary</h2>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<% for (int i = 0; i < Model.Count; i++) { %>
**// This is there I am stuck!**
<% } %>
<p>
<input type="submit" value="Submit" />
</p>
<% } %>
</asp:Content>