配制文件appsettings和Classes来自12节

在HomeController增加如下代码,使用IOption方式进行注入

 public class HomeController : Controller
{
private readonly Classes _classes;
public HomeController(IOptions<Classes> classesAccesster)
{
_classes = classesAccesster.Value;
}
public IActionResult Index()
{
return View(_classes);
}
}

在Index.cshtml使用绑定的文件

发现在HomeController要注入Option有些麻烦,可直接在cshtml直接注入

13-在Core Mvc中使用Options的更多相关文章

  1. 【ASP.NET Core快速入门】(五)命令行配置、Json文件配置、Bind读取配置到C#实例、在Core Mvc中使用Options

    命令行配置 我们通过vs2017创建一个控制台项目CommandLineSample 可以看到现在项目以来的是dotnet core framework 我们需要吧asp.net core引用进来,我 ...

  2. 菜鸟入门【ASP.NET Core】5:命令行配置、Json文件配置、Bind读取配置到C#实例、在Core Mvc中使用Options

      命令行配置 我们通过vs2017创建一个控制台项目CommandLineSample 可以看到现在项目以来的是dotnet core framework 我们需要吧asp.net core引用进来 ...

  3. asp.net core-7.在Core Mvc中使用Options

    1,添加asp.net core mvc应用程序 2,添加Controllers控制器文件夹,Views视图文件夹 然后在Startup类中ConfigureServices方法中注册一下servic ...

  4. 任务13:在Core Mvc中使用Options

    13 新建Controllers文件夹,在里面添加HomeController控制器 新建Views文件夹,再新建Home文件夹.再新建Index.cshtml的视图页面 注释上节课的代码,否则我们的 ...

  5. 在.net core Mvc中使用Options和IOptionsSnapshot

    1.Startup.cs 下代码 using System; using System.Collections.Generic; using System.Linq; using System.Thr ...

  6. 008.Adding a model to an ASP.NET Core MVC app --【在 asp.net core mvc 中添加一个model (模型)】

    Adding a model to an ASP.NET Core MVC app在 asp.net core mvc 中添加一个model (模型)2017-3-30 8 分钟阅读时长 本文内容1. ...

  7. 在ASP.NET Core MVC中子类Controller拦截器要先于父类Controller拦截器执行

    我们知道在ASP.NET Core MVC中Controller上的Filter拦截器是有执行顺序的,那么如果我们在有继承关系的两个Controller类上,声明同一种类型的Filter拦截器,那么是 ...

  8. NET Core MVC中创建PDF

    使用Rotativa在ASP.NET Core MVC中创建PDF 在本文中,我们将学习如何使用Rotativa.AspNetCore工具从ASP.NET Core中的视图创建PDF.如果您使用ASP ...

  9. ASP.NET Core MVC 中的 [Controller] 和 [NonController]

    前言 我们知道,在 MVC 应用程序中,有一部分约定的内容.其中关于 Controller 的约定是这样的. 每个 Controller 类的名字以 Controller 结尾,并且放置在 Contr ...

  10. ASP.NET Core MVC 中设置全局异常处理方式

    在asp.net core mvc中,如果有未处理的异常发生后,会返回http500错误,对于最终用户来说,显然不是特别友好.那如何对于这些未处理的异常显示统一的错误提示页面呢? 在asp.net c ...

随机推荐

  1. 《SQLServer删除重复数据的方法》

    方法一: declare @max integer,@id integer open cur_rows fetch cur_rows into @id,@max begin set rowcount ...

  2. 移动端absolute元素居中

    <div class="db"> <div class="dm"></div> </div> .db{ widt ...

  3. SQL Union和Union All使用方法

    格式: [SQL 语句 1]UNION [SQL 语句 2] 对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序: select ID,NAME from A UNION select I ...

  4. Stuts2的 "struts.devMode" 设置成true后,不起作用,仍需要重启tomcat

    不要用 <constant name="struts.devMode" value="true" />改成: <constant name=& ...

  5. Linq to Sql 左连接 , 取右表可能为 null的 int类型字段

    linq to sql , linq to entity 遇到一个问题, 主表, 从表 一对一 关系,  主表有记录, 从表 可能没有记录. 现在要查询 主表+从表 的某几个字段. 从表字段 有的是 ...

  6. 腾讯云“动态加速”与“CDN”的区别——浅谈对“动态加速”的理解(可能有误)

    CDN的劣势及“动态加速”产生背景 通常CDN对静态内容支持较好,若使用其加速动态内容,可能会导致异常(如导致无法登录).当然,可以将动态内容的在CDN节点上的缓存时间设置为0秒来解决.但这毕竟是用户 ...

  7. leetcode: 哈希——two-sum,3sum,4sum

    1). two-sum Given an array of integers, find two numbers such that they add up to a specific target ...

  8. Xcode 自定义控件创建及触发事件

    #pragma mark 控制器的view加载完毕的时候调用 //一般在这里进行界面的初始化 - (void)viewDidLoad { [super viewDidLoad]; NSLog(@&qu ...

  9. 进程—内存描述符(mm_struct)

    http://blog.csdn.net/qq_26768741/article/details/54375524 前言 上一篇我们谈论了task_struct这个结构体,它被叫做进程描述符,内部成员 ...

  10. BestCoder Round #89 1002 Fxx and game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5945 分析: 很容易想到用bfs,然而会超时,几乎是O(xt)了 这里用单调队列优化, 首先反着来,f ...