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

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

        public IActionResult Index()
        {
            return RedirectToAction("Index", "Main");//重定向=>Main/Index
        }

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

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

需要用[FromBody]来接收

 $.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. Web开发(分层解耦)

    2024-07-19 05:12:07       27 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 05:12:07       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 05:12:07       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 05:12:07       58 阅读
  4. Python语言-面向对象

    2024-07-19 05:12:07       69 阅读

热门阅读

  1. 分布式唯一id的7种方案

    2024-07-19 05:12:07       25 阅读
  2. 编程中的智慧之设计模式三

    2024-07-19 05:12:07       22 阅读
  3. 解决用PicGo为typora配置github图床失败的问题

    2024-07-19 05:12:07       19 阅读
  4. shape_trans 变换区域的形状

    2024-07-19 05:12:07       22 阅读
  5. 【21】读感 - 架构整洁之道(三)

    2024-07-19 05:12:07       15 阅读
  6. Bootstrap 5:现代前端开发的新篇章

    2024-07-19 05:12:07       17 阅读
  7. python 乌龟绘图

    2024-07-19 05:12:07       19 阅读
  8. qt 国际化语言,英文和中文切换

    2024-07-19 05:12:07       17 阅读
  9. 翁恺-C语言程序设计-10-4. 字符串循环左移

    2024-07-19 05:12:07       17 阅读
  10. 智能灯光控制系统可以控制哪些场景

    2024-07-19 05:12:07       18 阅读
  11. 20240718训练题目

    2024-07-19 05:12:07       15 阅读
  12. Python--input()函数

    2024-07-19 05:12:07       18 阅读