[Mac OS developing. NET Core] a simple WEB program

In the last article, we mentioned the option of developing under Mac OS.
We've got the tools ready.
Now let's make a simple DEMO

Create WEB program

We have created WEB program before and successfully run data

Now let's create a page and display it.

In our system, the most common one is Grid list.

Let's create a list interface

Grid list

Create a Model first
A simple user class, very simple

using System;

namespace WEB._01.Models
    public class UserModel
        /// <summary>
        /// ID
        /// </summary>
        public int UserId { get; set; }
        /// <summary>
        /// Name
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        ///Registration time
        /// </summary>
        public DateTime RegDateTime { get; set; }

Then create a UserController

using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using WEB._01.Models;

namespace WEB._01.Controllers
    public class UserController : Controller
        // GET
        public IActionResult Index()
            var user = new List<UserModel>();

            for (int i = 0; i < 10; i++)
                user.Add(new UserModel()
                    UserId = i,
                    UserName = i+1.ToString()+" name",
                    RegDateTime = DateTime.Now.AddDays(-i)
            return View(user);

Note here that the entity is assigned a value first, and then the data is returned to the foreground.

Then create a User directory in the Views directory and a View
The directory structure is as follows:

Then create the Index directly
The code is as follows:

@model List<UserModel>

    ViewBag.Title = "User list";
    Layout = "_Layout";

<h2>User list</h2>
<div class="panel panel-default todo-panel">
    <div class="panel-heading">@ViewData["Title"]</div>

    <table class="table table-hover">
            <td>user ID</td>
            <td>User name</td>
            <td>Registration time</td>

        @foreach (var item in Model)


Create a Table and generate data.

ok, add the last step to the navigation bar.

Under views > Share

Join the navigation bar.

OK. Let's run it to see the effect.

Click the new function we added [user list]

The effect is as follows:

So far, we have finished our new function.

Tags: ASP.NET Mac

Posted on Mon, 02 Dec 2019 08:08:05 -0800 by 2005