Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc JsonResult不包含接受0个参数的构造函数_Asp.net Mvc_Reactjs - Fatal编程技术网

Asp.net mvc JsonResult不包含接受0个参数的构造函数

Asp.net mvc JsonResult不包含接受0个参数的构造函数,asp.net-mvc,reactjs,Asp.net Mvc,Reactjs,当我遇到这个问题时,我正在通过一个教程学习ReactJS。一些人建议添加一个构造函数,如 public JsonResult() { } 这也不管用 using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; namespace ReactWithMVCPart1.Properties {

当我遇到这个问题时,我正在通过一个教程学习ReactJS。一些人建议添加一个构造函数,如

public JsonResult()
{
}
这也不管用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace ReactWithMVCPart1.Properties
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult Getmessage()
        {
            return new JsonResult { Data = "Hello World. I am from server-side" };
        }
    }
}

参考教程链接:

扩展ADyson的答案:对我有用的是

return new JsonResult ( new { Data = "Hello World. I am from server-side" } );
或者,更有用一点:

JsonResult result = new JsonResult ( new {} );
您现在可以做一些工作,并使用

result.Value = new { success = false };

扩展ADyson的回答:对我有效的是

return new JsonResult ( new { Data = "Hello World. I am from server-side" } );
或者,更有用一点:

JsonResult result = new JsonResult ( new {} );
您现在可以做一些工作,并使用

result.Value = new { success = false };

从代码来看,您似乎在使用ASP.NET核心MVC,但本教程是针对“传统”ASP.NET MVC的。就类的定义和使用方式而言,这两个框架之间可能存在差异。查看.NET Core:的文档,了解如何使用JsonResult。我希望
返回新的JsonResult({Data=“helloworld.I from server-side”})应该可以解决这个问题。从您的代码来看,您似乎在使用ASP.NET核心MVC,但本教程是针对“传统”ASP.NET MVC的。就类的定义和使用方式而言,这两个框架之间可能存在差异。查看.NET Core:的文档,了解如何使用JsonResult。我希望
返回新的JsonResult({Data=“helloworld.I from server-side”})应该可以解决这个问题。现在出现的错误是“JsonResult不包含带1个参数的构造函数”您使用的是什么框架?和/或什么json库?错误现在显示为“JsonResult不包含带1个参数的构造函数”您使用的是什么框架?和/或什么json库?