我使用MVC 2.0與Html.ListBoxFor如下定義無參數的構造函數:system.missingMethodException而:此對象
<% using (Html.BeginForm()) { %>
<input type="submit" value=">" />
<%= Html.ListBoxFor(x => x.lstTest, new MultiSelectList(new [] {"someone", "crap", "why"})) %>
<% } %>
當我點擊提交輸入下面什麼也沒有選擇按鈕,回發好的,當我選擇列表框中的3個項目之一時,它會拋出此錯誤:
System.MissingMethodException: No parameterless constructor defined for this object.
任何想法?這裏是我的控制器代碼:
[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 2010-08-13 14:19:39
你可以發佈你的控制器代碼嗎? – 2010-08-13 14:49:43
發表於上面,謝謝 – Whyyy 2010-08-13 15:08:28