首页 > 解决方案 > 独立运行React Native,独立运行MVC时调用MVC动作方法

问题描述

我在本机反应中有一个 fetch 调用:

        componentDidMount(){
        
        fetch("https://localhost:44379/GetShoppingItems/")
            .then((res) => {
            })
            .catch(() => {
            })   
    }

在 mvc 中:

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

            namespace sush.Controllers
            {
                public class SushController : Controller
                {
                    public IActionResult Index()
                    {
                        return View();
                    }

                    [HttpGet]
                    [Route("GetShoppingItems")]
                    public JsonResult GetShoppingItems()
                    {


                        return Json(new { });

                    }
                }


            }

如何从我的反应原生应用程序本地调用 api?

标签: asp.net-mvcreact-native

解决方案


推荐阅读