JSON:500(服务器内部服务器错误)的.NET MVC3 [英] JSON: 500 (Internal server server error) in .NET MVC3

查看:130
本文介绍了JSON:500(服务器内部服务器错误)的.NET MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到一些JSON功能的工作,它基本上是一样简单,因为它可以,但由于某种原因,我得到我的控制台上的一个500内部服务器错误和应用程序永远不会到达控制器。我试过刚才的一切,但code是这么简单我已经放弃了试图通过一遍又一遍看书同一对夫妇线来纠正错误。

I'm trying to get some JSON functionality to work, it's basically as simple as it can be but for some reason I'm getting a 500 Internal server error on my console and the application never reaches the controller. I've tried just about everything, but the code is so simple I've given up trying to find the error by readin the same couple of lines over and over.

下面是我的脚本:

            $("#saveAdvisorOption").click(function () {
            // Create a JSON object:
            alert("OK");
            var OptionsModel = { "AdvisorNewsFeed": $("#advisorCheckBox").val() };
            alert($(OptionsModel.AdvisorNewsFeed));
            $.post("/Account/ChangeOptionForAdvisor", OptionsModel, function (data) {

            });
        });

下面是我的模型:

    public class OptionsModel
{
    public string AdvisorNewsFeed { get; set; }

    public OptionsModel(string AdvisorNewsFeed)
    {
        this.AdvisorNewsFeed = AdvisorNewsFeed;

    }
}

}

这是我的控制器:

    public class AccountController : Controller
{
    [HttpPost]
    public ActionResult ChangeOptionForAdvisor( OptionsModel option)
    {

        //Return something
        return Json(option, JsonRequestBehavior.AllowGet);
    }

我对return语句一个破发点,但它永远不会运行。

I have a break point on the return statement but it is never run.

任何帮助是极大AP preciated。

Any help is greatly appreciated.

推荐答案

您可能只需要一个空的构造添加到 OptionsModel 类。 MVC不能实例化类没有一个空的构造。

You probably just need to add an empty constructor to the OptionsModel class. MVC can't instantiate the class without an empty constructor.

这篇关于JSON:500(服务器内部服务器错误)的.NET MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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