zoukankan      html  css  js  c++  java
  • 03. Asp.Net Core 3.x 笔记 View相关

    Layout

    Shared/_Layout.cshtml

    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>@ViewBag.Title</title>
        <environment include="Development">
            <link rel="stylesheet" asp-href-include="css/*" asp-href-exclude="css/all.min.css" />
        </environment>
        <environment exclude="Development">
            <link rel="stylesheet" asp-href-include="all.min.css" />
        </environment>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-md-2">
                    <img asp-append-version="true" alt="Logo" src="images/index.png" style="height:60px;" />
                </div>
                <div class="col-md-10">
                    <span class="h2">@ViewBag.Title</span>
                </div>
    
            </div>
            <div class="row">
                <div class="col-md-12">
                    @RenderBody()
                </div>
            </div>
        </div>
    </body>
    </html>
    

    _ViewStart.cshtml

    @{
        Layout = "_Layout";
    }
    
    

    TagHelper

    _ViewImports.cshtml

    @addTagHelper "*,Microsoft.AspNetCore.Mvc.TagHelpers"
    

    使用:Index.cshtml

    
          <a asp-action="Add">Add</a>
          ...
              <a asp-controller="Employee" asp-action="Index" asp-route-departmentId="@Model.Id">
                    Employees
               </a>
    

    DisplayTemplates

    • Views/Empployee/DisplayTemplates/Index.cshtml
    @using Three.Models
    @model IEnumerable<Employee>
    <div class="row">
        <div class="col-md-10 offset-md-2">
            <table class="table">
                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Gender</th>
                    <th>IsFire</th>
                    <th>操作</th>
                </tr>
                <!--使用DisplayTemplates-->
                @Html.DisplayForModel()
            </table>
        </div>
    </div>
    <div class="row">
        <div class="col-md-4 offset-md-2">
            <a asp-action="Add" asp-route-departmentId="@ViewBag.DepartmentId" >Add</a>
    
        </div>
    </div>
    
    • Views/Empployee/DisplayTemplates/Employee.cshtml
    @using Three.Models
    @model Employee
    <form asp-action="Add">
        <input type="hidden" asp-for="DepartmentId"/>
        <div class="row form-group">
            <div class="col-md-2 offset-md-2">
                <label asp-for="FirstName"></label>
            </div>
            <div class="col-md-6">
                <input class="form-control" asp-for="FirstName" />
            </div>
        </div>
        <div class="row form-group">
            <div class="col-md-2 offset-md-2">
                <label asp-for="LastName"></label>
            </div>
            <div class="col-md-6">
                <input class="form-control" asp-for="LastName" />
            </div>
        </div>
        <div class="row form-group">
            <div class="col-md-2 offset-md-2">
                <label asp-for="Gender"></label>
            </div>
            <div class="col-md-6">
              @*  <input class="form-control" asp-for="Gender" />*@
                <select class="form-control" asp-for="Gender"
                        asp-items="Html.GetEnumSelectList<Gender>()">
    
                </select>
            </div>
        </div>
        <div class="row">
            <div class="col-md-2 offset-md-2">
                <button type="submit" class="btn btn-primary">Add</button>
            </div>
        </div>
    </form>
    
  • 相关阅读:
    LeetCode#237 Delete Node in a Linked List
    数据库概念
    请基于 TCP/IP 五层网络模型描述下当我们在浏览器请求 https ://pp.io 站点时,发生了哪些事情
    高并发大流量
    mysql关于索引
    php基础——会话控制
    php基础——运算符知识
    php基础——常量及数据类型考察
    引用变量和cow机制
    关系基本特性的运算封闭性
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/13030475.html
Copyright © 2011-2022 走看看