13

新建Controllers文件夹,在里面添加HomeController控制器

新建Views文件夹,再新建Home文件夹。再新建Index.cshtml的视图页面

任务13:在Core Mvc中使用Options

注释上节课的代码,否则我们的管道都会被抵消,最后只输出了。appsettings.json文件的内容

任务13:在Core Mvc中使用Options

注入MVC

添加默认路由,

这样就把整个MVC的middleware添加到我们的应用程序当中

任务13:在Core Mvc中使用Options

 

使用IOptions是一个泛型的方法,把我们的Class传进去,

 

任务13:在Core Mvc中使用Options

 

Controller内输出代码

任务13:在Core Mvc中使用Options

@model OptionsBindSample.Class
@{
    ViewData["Title"] = "Index";
}
<h2>Index</h2>
<h4>Class No: @Model.ClassNo</h4>
<h4>Class Desc: @Model.ClassDesc</h4>
<h3>
    Students:
</h3>
<div>
    @foreach (var student in Model.Students)
    {
        <span>Name: @student.Name</span>
        <span>Age: @student.Age</span>
    }
</div>
Index.cshtml

相关文章:

  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
猜你喜欢
  • 2021-09-25
  • 2021-06-24
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案