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: 后端没有回复');
     }
 });
相关推荐
码事漫谈1 天前
【精华】C++成员初始化列表完全指南:为什么、何时以及如何正确使用
后端
码事漫谈1 天前
C++ 强制类型转换:类型安全的多维工具
后端
Deng8723473481 天前
代码语法检查工具
linux·服务器·windows
开心香辣派小星1 天前
23种设计模式-15解释器模式
java·设计模式·解释器模式
Halo_tjn1 天前
虚拟机相关实验概述
java·开发语言·windows·计算机
RainbowSea1 天前
github 仓库主页美化定制
后端
摆烂z1 天前
Docker与Jib(maven插件版)实战
java
RainbowSea1 天前
从 Spring Boot 2.x 到 3.5.x + JDK21:一次完整的生产环境迁移实战
java·spring boot·后端
笨手笨脚の1 天前
Spring Core常见错误及解决方案
java·后端·spring
奶油松果1 天前
Springboot自动装配 - redis和redission
java·spring boot·redis