i created ViewModel to test this answer : How to fill ViewModel which has List<T> property after clicking submit button mvc 3?
i need checkboxlist look please WeeklyModel.Also WeeklyViewModel. i want to list alldoays in checkboxes. Nut my error below . it is stupid error. i can not understand reson to solve how to solve it? thanks... Look please helpful ( what i need artcile) article : When do I use View Models, Partials, Templates and handle child bindings with MVC 3 Models:
public class WeeklyModel
{
public string Name { get; set; }
public string Value { get; set; }
public bool IsChecked { get; set; }
}
public class WeeklyViewModel
{
public IEnumerable<WeeklyModel> Settings { get; set; }
public WeeklyViewModel()
{
Settings = new List<WeeklyModel>();
}
}
Controller:
public ActionResult CreateWeekly()
{
var model = new WeeklyViewModel();
List<WeeklyModel> li = new List<WeeklyModel>();
li.Add( new WeeklyModel(){ Name="Monday", Value="mon", IsChecked=false});
model.Settings = li;
return View(model);
}
[HttpPost]
public ActionResult CreateWeekly( WeeklyViewModel weekly)
{
return View("CreateWeekly", weekly);
}
i created Views/Trigger/EditorTemplates/WeeklyModels.aspx :
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/ChildSite.Master" Inherits="System.Web.Mvc.ViewPage<GenSystem.Models.WeeklyModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%:Html.CheckBoxFor(m=>m.IsChecked) %>
<%:Html.LabelFor(m=>m.IsChecked,Model.Name) %>
<%:Html.HiddenFor(m=>m.Name) %>
<%:Html.HiddenFor(m=>m.Value) %>
</asp:Content>
View :
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/ChildSite.Master" Inherits="System.Web.Mvc.ViewPage<GenSystem.Models.WeeklyViewModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
CreateWeekly
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
using (Html.BeginForm())
{
%>
<div>
<%:Html.EditorFor(m => m.Settings)%>
</div>
<br />
<input value="GenerateForWeekly" name="submitButton" type="submit" />
<%} %>
</asp:Content>
How to solve this Error:
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value)
at Transformer.NET.Token.ParseAnchors()
at Transformer.NET.TextTransformer.Parse(List1 tokensType, Dictionary
2 variables)
at Transformer.NET.TextTransformer.Transform(List1 tokensType, Dictionary
2 variables)
at Transformer.NET.TextTransformer.Transform(List`1 tokensType)
at Transformer.NET.TextTransformer.Transform()
at Ext.Net.ExtNetTransformer.Transform(String text)
at Ext.Net.InitScriptFilter.Transform()
at Ext.Net.InitScriptFilter.Flush()
at System.Web.HttpWriter.Filter(Boolean finalFiltering)
at System.Web.HttpResponse.FilterOutput()
at System.Web.HttpApplication.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)