Web开发:ASP.NET CORE的后端小结(基础)

1.后端重定向到指定路由

cs 复制代码
        public IActionResult Index()
        {
            return RedirectToAction("Index", "Main");//重定向=>Main/Index
        }

【备注】如果在MainController的Index方法中return View();本质是 return View("Index"),返回和方法同名的cshtml位置,即返回Main/Index.cshtml的页面;

2.后端接收前端AJAX的JSON数据

需要用[FromBody]来接收

javascript 复制代码
 $.ajax({
     url: '@Url.Action("ProcessStudent", "Main")',//将发送一个POST请求到MainController的ProcessStudent方法中
     type: 'POST',
     contentType: 'application/json',
     data: JSON.stringify(allStudents),//JSON格式发送
     success: function (response) {
         alert('后端成功响应: ' + response);
     },
     error: function () {
         alert('Error: 后端没有回复');
     }
 });
相关推荐
Victor3561 小时前
Redis(158)Redis的主从同步问题如何解决?
后端
Victor3561 小时前
Redis(159)Redis的集群问题如何解决?
后端
wanhengidc3 小时前
云计算时代 云手机与云服务器的不同
服务器·智能手机·云计算
后端小张3 小时前
【JAVA进阶】Spring Boot 核心知识点之自动配置:原理与实战
java·开发语言·spring boot·后端·spring·spring cloud·自动配置
tg-zm8899968 小时前
2025返利商城源码/挂机自动收益可二开多语言/自定义返利比例/三级分销理财商城
java·mysql·php·laravel·1024程序员节
X***C8628 小时前
SpringBoot:几种常用的接口日期格式化方法
java·spring boot·后端
j***29488 小时前
IPV6公网暴露下的OPENWRT防火墙安全设置(只允许访问局域网中指定服务器指定端口其余拒绝)
服务器·安全·php
i***t9198 小时前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
ao_lang8 小时前
数据链路层
linux·服务器·网络
前端达人8 小时前
你的App消息推送为什么石沉大海?看Service Worker源码我终于懂了
java·开发语言