system.missingMethodException而:此对象定义无参数的构造函数 [英] System.MissingMethodException: No parameterless constructor defined for this object

查看:158
本文介绍了system.missingMethodException而:此对象定义无参数的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC 2.0作为低于Html.ListBoxFor:

 <使用%(Html.BeginForm()){%GT;       <输入类型=提交值=>中/>        <%= Html.ListBoxFor(X => x.lstTest,新MultiSelectList(新[] {一个人,废话,为什么}))%GT;    <%}%GT;

当我点击提交输入下面什么也没有选择的按钮,这回发好,当我选择列表框中的3项之一,它抛出这个错误:

  system.missingMethodException而:此对象定义无参数的构造函数。

任何想法?这里是我的控制器code:

  [的HandleError]
公共类HomeController的:控制器
{
    公共HomeController的()
    {    }    公众的ActionResult指数()
    {
        计算机[消息] =测试工具;        返回查看();
    }    [HTTPGET]
    公众的ActionResult关于()
    {
        计算机[的myKey] =测试工具;        LogOnModel模式=新LogOnModel();
        model.lstTest =新MultiSelectList(新[] {A,B,C});        返回查看(模型);
    }
    [HttpPost]
    公众的ActionResult关于(LogOnModel模型)
    {
        计算机[的myKey] =测试工具;        model.lstTest =新MultiSelectList(新[] {});        返回查看(模型);
    }
}


解决方案

您是否有LogOnModel一个参数的构造函数?它需要一个用于DefaultModelBinder进行实例化。此外,当您发布异常,请从异常对象发布完整的堆栈跟踪,否则我们只是猜测那里的错误确实发生了。

I'm using MVC 2.0 with a Html.ListBoxFor as below:

<% using (Html.BeginForm()) { %>

       <input type="submit" value=">" />

        <%= Html.ListBoxFor(x => x.lstTest, new MultiSelectList(new [] {"someone", "crap", "why"})) %>

    <% } %>

When I click the input submit button below with nothing selected, it posts back fine, when I select one of the 3 items in the listbox it throws 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);
    }
}

解决方案

Does your LogOnModel have a parameterless constructor? It needs one for the DefaultModelBinder to instantiate it. Additionally, when you post the exception, please post the full stack trace from the exception object, else we're simply guessing where the error actually took place.

这篇关于system.missingMethodException而:此对象定义无参数的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆