zoukankan      html  css  js  c++  java
  • 12-optionBinding

    1-创建一个空的dotnet mvc网站

    2- 创建appsettings.json文件, 这文件会默认被绑定

    {
      "ClassNo": "1",
      "ClassDesc": "Asp.net core",
      "Students": [
        {
          "name": "lili",
          "age": "11"
        },
        {
          "name": "xiaofeng",
          "age": "33"
        },
        {
          "name": "xiaobao",
          "age": "66"
        }
      ]
    }
    

      3-创建一个可映射的class类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    
    namespace optionBindingDemo
    {
        public class Classes
        {
            public string ClassNo { get; set; }
    
            public string ClassDesc { get; set; }
    
            public List<Student> Students { get; set; }
        }
    
        public class Student
        {
            public string Age { get; set; }
            public string Name { get; set; }
        }
    }

    4-开始绑定

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Configuration;
    
    namespace optionBindingDemo
    {
        public class Startup
        {
            IConfiguration Configuration;
            public Startup(IConfiguration configuration)
            {
                this.Configuration = configuration;
            }
            // This method gets called by the runtime. Use this method to add services to the container.
            // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
            public void ConfigureServices(IServiceCollection services)
            {
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                Classes cls = new Classes();
                this.Configuration.Bind(cls);
                app.Run(async (context) =>
                {
                    await context.Response.WriteAsync($"ClassNo: {cls.ClassNo}");
                    await context.Response.WriteAsync($"ClassDesc: {cls.ClassDesc}");
                    await context.Response.WriteAsync($"studentListCount: {cls.Students.Count}");
                });
            }
        }
    }
  • 相关阅读:
    vue2.0之render函数
    vuex学习笔记
    js小知识点
    vue2.0路由进阶
    vue2.0使用slot插槽分发内容
    js事件机制
    firefox在引入vue.js后不支持e=e||window.event的解决办法
    qs.js使用方法
    除了使用URLSearchParams处理axios发送的数据,但是兼容性不好,其他的兼容方法
    定义设置滚动条
  • 原文地址:https://www.cnblogs.com/qinzb/p/9286809.html
Copyright © 2011-2022 走看看