I am using MVC 2.0 with Html.ListBoxFor as shown below:
<% using (Html.BeginForm()) { %> <input type="submit" value=">" /> <%= Html.ListBoxFor(x => x.lstTest, new MultiSelectList(new [] {"someone", "crap", "why"})) %> <% } %>
When I press the enter input button below, nothing is selected, it returns a message in the order, when I select one of the 3 items in the list, it gives this error:
System.MissingMethodException: No parameterless constructor defined for this object.
Any ideas? here is my controller code:
[HandleError] public class HomeController : Controller { public HomeController() { } public ActionResult Index() { ViewData["Message"] = "Test Harness"; return View(); } [HttpGet] public ActionResult About() { ViewData["mykey"] = "Test Harness"; LogOnModel model = new LogOnModel(); model.lstTest = new MultiSelectList(new [] {"A", "B", "C"}); return View(model); } [HttpPost] public ActionResult About(LogOnModel model) { ViewData["mykey"] = "Test Harness"; model.lstTest = new MultiSelectList(new [] { "" }); return View(model); } }
Whyyy source share