码迷,mamicode.com
首页 > Web开发 > 详细

[.NET Core 4]测试验证功能(相较于core教程属于新增)

时间:2016-08-11 20:49:39      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:

sqllite 的数据库迁移功能有限制

1)新增如下model,执行数据库迁移不能成功,参考此链接“http://stackoverflow.com/questions/35797628/ef7-generates-wrong-migrations-with-sqlite”

初步判断有限制,所以删除数据库,删除迁移文件,重建数据库“http://www.atove.com/Article/Details/87E62DFDDBF9EC0C5350E7ACD43BADDF”(这篇文章是非.net core环境下的,实验无法成功,以后有空再实验)

using System;
using System.ComponentModel.DataAnnotations; //手动高亮

namespace MvcMovie.Models
{
    public class People{
        public int ID { get; set; }

        // [Display(Name = "姓名")]
        public string Name { get; set; }

        // [Display(Name = "年龄")]
        public int Age { get; set; }
    }
}

2)数据库OK

3)新增控制器PeopleController.cs,新增View目录“People”和视图文件Index.cshtml 

 

public async Task<IActionResult> Index()  
        {
            return View(await _context.People.ToListAsync());
        }
@model IEnumerable<MvcMovie.Models.People>

@{
    ViewData["Title"] = "Index";
}

<h2>ViewData["Title"]</h2>
<p>
    <a asp-action="Create">Create New</a>
</p>


<table class="table">
    <thead>
        <tr>
            <th>
                <!--Html.DisplayNameFor(model => model.Genre)-->
                @Html.DisplayNameFor( model => model.Name ) 
            </th>
            <th>
                @Html.DisplayNameFor( model => model.Age )
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model) {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.Name) 
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Age) 
                    </td>
                    <td>
                        <a asp-action="Edit" asp-route-id="@item.ID">Edit</a> |       
                        <a asp-action="Details" asp-route-id="@item.ID">Details</a> |  
                        <a asp-action="Delete" asp-route-id="@item.ID">Delete</a>      
                    </td>
                </tr>
        }
    </tbody>
</table>

4)C# 中参数验证方式的演变

 

 

[.NET Core 4]测试验证功能(相较于core教程属于新增)

标签:

原文地址:http://www.cnblogs.com/mspeer/p/5762306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!