zoukankan      html  css  js  c++  java
  • ABP 极简入门教程(二 MVC方式显示数据)

    增加显示菜单

    Sample.Web.MVC项目中找到startup目录打开SampleNavigationProvider.cs,根据现有内容添加以下内容

    .AddItem(
                        new MenuItemDefinition(
                            PageNames.Address,
                            L("Address"),
                            url: "Address",
                            icon: "fas fa-address-book"
                        )
                    )

    打开相同目录的PageNames.cs增加页面名称

    public const string Address = "Address";

    如果需要多语言环境需要到Sample.core项目下LocalizationSourceFilesSample-zh-Hans.xml增加一行

    <text name="Address">联系人</text>

    在Models目录下新建Address目录并添加AddressListViewModel.cs视图模型

    using System.Collections.Generic;
    using Sample.Northwind.Dto;
    
    namespace Sample.Web.Models.Address
    {
        public class AddressListViewModel
        {
            public IReadOnlyList<AddressDto> Address { get; set; }
        }
    }

    在MVC项目中增加Address控制器

    using System.Threading.Tasks;
    using Sample.Controllers;
    using Sample.Northwind;
    using Sample.Web.Models.Address;
    using Microsoft.AspNetCore.Mvc;
    
    namespace Sample.Web.Controllers
    {
        public class AddressController : SampleControllerBase
        {
            private readonly IAddressAppService _addressAppService;
    
            public AddressController(IAddressAppService addressAppService)
            {
                _addressAppService = addressAppService;
            }
            public async Task<ActionResult> Index()
            {
                var result = (await _addressAppService.GetAllAsync()).Items;
                var model = new AddressListViewModel()
                {
                    Address = result
                };
                return View(model);
            }
        }
    }

    添加视图

    @model Sample.Web.Models.Address.AddressListViewModel
    @{
        ViewData["Title"] = "Index";
    }
    
    <div class="content-header">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="m-0 text-dark">@L("Address")</h1>
                </div>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            <table class="table table-bordered">
                                <tr>
                                    <th>编号</th>
                                    <th>姓名</th>
                                    <th>邮箱</th>
                                </tr>
                                @foreach (var item in Model.Address)
                                {
                                    <tr>
                                        <td>@item.Id</td>
                                        <td>@item.Name</td>
                                        <td>@item.Email</td>
                                    </tr>
                                }
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    显示效果如下

  • 相关阅读:
    了解node.js
    RC4 in TLS is Broken: Now What?
    LDAP 在ubuntu14.04下的安装配置install and configure
    Bucking the stigma (留学生请摘掉有色眼镜看社区大学)
    SSL Labs: Increased Penalty When TLS 1.2 Is Not Supported
    PostgresQL中的NUlls first/last功能
    网页小工具集合
    T-SQL在线格式化工具
    sudoers文件解析
    Java提高篇——JVM加载class文件的原理机制
  • 原文地址:https://www.cnblogs.com/liessay/p/13100144.html
Copyright © 2011-2022 走看看