我认为我的看法是,我的看法是,从一个没有装满页的空洞田中获取价值,或者根本不产生,只是从《示范公约》中获取:
观点:
namespace Projeto_Vendedores.Models.ViewModels
{
public class SellerFormViewModel
{
public Seller Seller { get; set; }
public ICollection<Department> Departments { get; set; }
}
}
模式:
using Projeto_Vendedores.Migrations;
namespace Projeto_Vendedores.Models
{
public class Seller
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public double BaseSalary { get; set; }
public DateTime BirthDate { get; set; }
public Department Department { get; set; }
public int DepartmentId { get; set; }
public ICollection<SalesRecord> Sales { get; set; } = new List<SalesRecord>();
public Seller()
{
}
public Seller(int id, string name, string email, double baseSalary, DateTime birhtDate, Department department)
{
Id = id;
Name = name;
Email = email;
BaseSalary = baseSalary;
BirthDate = birhtDate;
Department = department;
}
}
}
主计长:
using Microsoft.AspNetCore.Mvc;
using Projeto_Vendedores.Models;
using Projeto_Vendedores.Models.ViewModels;
using Projeto_Vendedores.Services;
namespace Projeto_Vendedores.Controllers
{
public class SellersController : Controller
{
private readonly SellerService _sellerService;
private readonly DepartmentService _departmentService;
public SellersController(SellerService sellerService, DepartmentService departmentService)
{
_sellerService = sellerService;
_departmentService = departmentService;
}
public IActionResult Index()
{
var list = _sellerService.FindAll();
return View(list);
}
public IActionResult Create()
{
var departments = _departmentService.FindAll();
var viewModel = new SellerFormViewModel { Departments = departments };
return View(viewModel);
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(Seller obj)
{
_sellerService.Insert(obj);// it just add to the database and save changes
return RedirectToAction(nameof(Index));
}
}
}
建立表格(POST):
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@model Projeto_Vendedores.Models.ViewModels.SellerFormViewModel
@{
ViewData["Title"] = "Create";
}
<h1>@ViewData["Title"]</h1>
<h4>Seller</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div class="form-group">
<label asp-for="Seller.Name" class="form-label"></label>
<input asp-for="Seller.Name" class="form-control" />
</div>
<div class="form-group">
<label asp-for="Seller.Email" class="form-label"></label>
<input asp-for="Seller.Email" class="form-control" />
</div>
<div class="form-group">
<label asp-for="Seller.BirthDate" class="form-label"></label>
<input asp-for="Seller.BirthDate" class="form-control" />
</div>
<div class="form-group">
<label asp-for="Seller.BaseSalary" class="form-label"></label>
<input asp-for="Seller.BaseSalary" class="form-control" />
</div>
<div class="form-group">
<label asp-for="Seller.DepartmentId" class="control-label"></label>
<select asp-for="Seller.DepartmentId" asp-items="@(new SelectList(Model.Departments,"Id", "Name"))" class="form-control"></select>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
......
我只想正确阅读数据,但每次我尝试,申请都会停止,我只举一个例外,告诉我,第一个记录领域是无效的,其余也是无效的。