带有.NET MVC的jQuery getJSON无法正常工作 [英] jQuery getJSON with .NET MVC not working

查看:76
本文介绍了带有.NET MVC的jQuery getJSON无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当页面在我的.NET MVC应用中加载时,我已经设置了getJSON调用:

I have setup a getJSON call when page loads in my .NET MVC app like this:

$(document).ready(function(){
   $.getJSON("/Administrator/GetAllUsers", function (res) {

            // getting internal server error here...
        });

});

动作如下:

  [HttpGet]
    [ActionName("GetAllUsers")]
    public string GetAllUsers()
    {
        return new JavaScriptSerializer().Serialize(ctx.zsp_select_allusers().ToList());
    }

我收到此错误:

500 (Internal Server Error)

我在这里做错了什么?

推荐答案

尝试

$.getJSON('@Url.Action("GetAllUsers", "Administrator")', function (res)   {

            alert(res);
        });

 [HttpGet]
    public ActionResult GetAllUsers( ) {

          //get the data from db , then send it
          //i'm passing dummy text 'got it'

        return Json("got it", JsonRequestBehavior.AllowGet);
    }

这篇关于带有.NET MVC的jQuery getJSON无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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