【问题标题】:How to return JSON as a REST API without changing the routing of the page?如何在不更改页面路由的情况下将 JSON 作为 REST API 返回?
【发布时间】:2013-12-11 03:34:10
【问题描述】:

使用 Angular 的 POST 请求后,服务器发回 404 错误。我希望 ActionResult 在不重定向或重新加载页面的情况下返回 JSON。

ASP.NET MVC(服务器):

public ActionResult Patient(LoginModel.UserInfo Model){
 //code is here 
 return Json(Info, JsonRequestBehavior.AllowGet);
}

【问题讨论】:

  • 嗨,您使用的是 AJAX 发布请求吗?

标签: c# asp.net json angularjs


【解决方案1】:

使用HttpPost 属性装饰您的操作。您的操作可能只针对 GET 请求。此外,由于您正在处理 POST 请求,因此您无需为 JSON 响应指定 AllowGet

[HttpPost]
public JsonResult Patient(LoginModel.UserInfo Model)
{
    //code is here 
    return Json(Info);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-21
    • 2019-03-28
    • 2012-06-02
    • 2018-01-11
    • 2014-05-11
    • 2011-09-01
    • 2022-10-15
    • 2019-11-22
    相关资源
    最近更新 更多