首页 > Web开发 > 详细

03. Asp.Net Core 3.x 笔记

时间:2020-06-02 13:24:04      阅读:50      评论:0      收藏:0      [点我收藏+]

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>

03. Asp.Net Core 3.x 笔记

原文:https://www.cnblogs.com/easy5weikai/p/13030475.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!