首页 > 其他分享 >MVC控件器动作 返回类型 IActionResult

MVC控件器动作 返回类型 IActionResult

时间:2023-02-07 15:12:07浏览次数:42  
标签:控件 IActionResult Id MVC Student new public Name

 1 using Microsoft.AspNetCore.Mvc;
 2 using System.Diagnostics;
 3 using System.Text;
 4 using TestMvcWebApplication.Models;
 5 
 6 namespace TestMvcWebApplication.Controllers
 7 {
 8     public class HomeController : Controller
 9     {
10         private readonly ILogger<HomeController> _logger;
11 
12         public HomeController(ILogger<HomeController> logger)
13         {
14             _logger = logger;
15         }
16 
17         public IActionResult Index()
18         {
19             Student student = new Student();
20             student.Id = 1;
21             student.Name = "Test";
22             List<Student> students = new List<Student>();
23             students.Add(student);
24             student = new Student { Id = 2, Name = "张三" };
25             students.Add(student);
26             return View(students);
27         }
28 
29         public IActionResult Privacy()
30         {
31             return View();
32         }
33         public IActionResult Test()
34         {//重定向
35             return RedirectToAction("Index");
36         }
37         public IActionResult ShowJson()
38         {//返回Json数据,中文不进行编码
39             List<Student> list = new List<Student>
40             {
41                 new Student { Id=1,Name="张三" },
42                 new Student { Id=2,Name="李四"},
43                 new Student { Id=3,Name="王五"},
44             };
45             return Ok(list);
46         }
47         public IActionResult ShowJson2()
48         {//返回Json数据,中文已编码
49             List<Student> list = new List<Student>
50             {
51                 new Student { Id=1,Name="张三" },
52                 new Student { Id=2,Name="李四"},
53                 new Student { Id=3,Name="王五"},
54             };
55             return Json(list);
56         }
57         public IActionResult Down()
58         {//下载文件
59             using MemoryStream ms = new MemoryStream();
60             string content = "深圳欢迎您!";
61             ms.Write(Encoding.UTF8.GetBytes(content));
62             return File(ms.ToArray(), "application/octet-stream", "hello.txt");
63         }
64         public IActionResult Content()
65         {//返回文本
66             return Content("返回文本");
67         }
68 
69         [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
70         public IActionResult Error()
71         {
72             return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
73         }
74     }
75     public class Student
76     {
77         public int Id { get; set; }
78         public string Name { get; set; }
79     }
80 }

 

标签:控件,IActionResult,Id,MVC,Student,new,public,Name
From: https://www.cnblogs.com/friend/p/17098466.html

相关文章

  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:MarqueeLabel
    本文简述如何在Smobiler中使用MarqueeLabel。Step1.新建一个SmobilerForm窗体,并在窗体中加入MarqueeLabel,控件Size设置(300,30),布局如下MarqueelLabel可以直接在设计器......
  • 图表控件LightningChart.NET 系列教程(八):LightningChart 组件——从工具箱添加至 Windo
    LightningChar​t.NET​ SDK是一款高性能数据可视化插件工具,由数据可视化软件组件和工具类组成,可支持基于Windows 的用户界面框架(WindowsPresentationFoundation)、Win......
  • MySQL 的 MVCC 的工作原理
    InnoDB引擎通过什么技术来保证事务的四个特性的呢?持久性是通过redolog(重做日志)来保证的;原子性是通过undolog(回滚日志)来保证的;隔离性是通过MVCC(多版本并发控制)......
  • Spring—Spring MVC 全解析
    处理流程SpringMVC处理流程.PNG用户发送请求至前端控制器DispatcherServlet;DispatcherServlet收到请求调用HandlerMapping处理器映射器;处理器映射器找到具体的处理器(......
  • (原创)【B4A】一步一步入门02:可视化界面设计器、控件的使用
    一、前言上篇(原创)【B4A】一步一步入门01:简介、开发环境搭建、HelloWorld中我们创建了默认的项目,现在我们来看一下B4A项目的构成,以及如何所见即所得的设计界面,并添加和使......
  • vue3 + ts 封装树形控件
    vue3+ts封装树形控件父组件调用 <TreeFilter label="name" title="部门列表(单选)" :requestApi="getUserDepartment" :defaultValue="treeFilterValue.depar......
  • 我常用的delphi 第三方控件
     有网友问我常用的控件及功能。我先大概整理一下,以后会在文章里面碰到时再仔细介绍。     DevexpressVCL这个基本上覆盖了系统界面及数据库展示的方方面面,......
  • Android控件之EditView探究
    EditView类继承自TextView类,EditView与TextView最大的不同就是用户可以对EditView控件进行编辑,同时还可以为EditView控件设置监听器,用来判断用户的输......
  • SpringMVC-超大文件上传-如何上传文件-大文件上传
    ​ 我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用。首先我们需要了解的是上传文件三要素:1.表单提交方式......
  • 浅析MySql中的MVCC机制
    前言本文将分析mvcc的机制和工作原理并举例说明。话不多说,直入主题MVCC机制是什么MVCC,英文全称MultiversionConcurrencyControl,多版本并发控制。简单理解,就是相当于给......