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: 后端没有回复');
     }
 });
相关推荐
刘大猫.8 分钟前
XNMS项目-拓扑图展示
java·人工智能·算法·拓扑·拓扑图·节点树·xnms
正在努力Coding5 小时前
SpringAI - 工具调用
java·spring·ai
Loo国昌6 小时前
【LangChain1.0】第五阶段:RAG高级篇(高级检索与优化)
人工智能·后端·语言模型·架构
小丑西瓜6666 小时前
CMake基础用法,cmake_minimum_required,project,add_executable
linux·服务器·c++·camke
晚风吹长发6 小时前
初步了解Linux中的命名管道及简单应用和简单日志
linux·运维·服务器·开发语言·数据结构·c++·算法
我尽力学6 小时前
面试 总结
java·spring boot·面试
爬台阶的蚂蚁6 小时前
Spring AI Alibaba基础概念
java·spring·ai
计算机学姐6 小时前
基于SpringBoot的演唱会抢票系统
java·spring boot·后端·spring·tomcat·intellij-idea·推荐算法
全栈测试笔记6 小时前
异步函数与异步生成器
linux·服务器·前端·数据库·python
huohuopro6 小时前
Mybatis的七种传参方式
java·开发语言·mybatis