ASP.net MVC 2 EditorFor Dictionary Bind
I try this, but 开发者_如何学Pythondon't work.
bemutatkozas@Modify = null all the time.
public class Iroda
{
public Dictionary<int,string> bemutatkozas { get; set; }
}
public ActionResult Index()
{
var dct = new Dictionary<int, string>();
dct.Add(1, "magyar");
dct.Add(2, "angol");
dct.Add(3, "olasz");
return View(new Iroda { bemutatkozas = dct });
}
[HttpPost]
public ActionResult Modify(Dictionary<int,string> bemutatkozas)
{
return View();
}
<% using (Html.BeginForm("Modify","Iroda"))
{%>
<%= Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<%= Html.EditorFor(o=>o.bemutatkozas,"MultiLanguageEditor") %>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% } %>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Dictionary<int, string>>" %>
<% int i = 0; %>
<% foreach (var s in Model)
{ %>
<%= Html.Hidden(Html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix+"["+i+"].key", s.Key) %>
<%= Html.TextBox(Html.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix+"["+i+"].value",s.Value) %>
<% i++; %>
<% }%>
Whats the solution? Thx!
精彩评论