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: 后端没有回复');
     }
 });
相关推荐
摇滚侠4 小时前
《SpringBoot 3:入门与应用实战》第 12 章 JDBC 与事务 使用 JdbcTemplate 阅读笔记 32
spring boot·笔记·后端
phltxy4 小时前
C语言操作符详解
java·c语言·算法
毕竟是shy哥4 小时前
vs code连接远程服务器docker环境及配置免密登录
服务器·docker·vs code
步行cgn5 小时前
@Configuration 详解:Spring 配置类的核心注解
java·后端·spring
徐小黑ACG5 小时前
nginx配置文件
linux·服务器·nginx
sunshine22 girl5 小时前
Java学习一 环境配置2 安装和基本使用Idea
java·学习·intellij-idea
新时代牛马5 小时前
Linux VFS 完整篇:从path_openat、dentry/inode 到page cache 与挂载排障
linux·运维·服务器
嘿嘿-667 小时前
Windows 一键使用 GPT-6 Astra:Codex CLI 配置教程
java·人工智能·windows·gpt·chatgpt·web
桦说编程7 小时前
【AtomicAgent系列1】变异测试——过去做不起,现在 agent 做得起
后端·ai编程·vibecoding
新时代牛马8 小时前
Linux 驱动中断与定时完整篇:从 request_threaded_irq 到hrtimer 选型与排障
linux·运维·服务器