我有一个 ASP.NET Core MVC 应用程序。有一个用于编辑组的表格。
来自控制器的代码:
public IActionResult EditGroup(int? id)
{
if (id != null)
{
var group = _unitOfWork.Groups.Get((int)id);
if (group != null)
return View(group);
}
return NotFound();
}
[HttpPost]
public IActionResult EditGroupPost(Group group)
{
_unitOfWork.Groups.Update(group);
_unitOfWork.Save();
return RedirectToAction("Index");
}
查看代码:
@model University.Core.Models.Group
@{
ViewData["Title"] = "EditGroup";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>Edit Group</h1>
<form asp-action="EditGroupPost" asp-controller="home" asp-route-id="@Model.Id">
<div class="form-group">
<label asp-for="Name" class="control-label">Name</label>
<input type="text" asp-for="Name" class="form-control" />
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</form>
团体课:
public class Group
{
public int Id { get; set; }
public int CourseId { get; set; }
public string Name { get; set; }
}
输入Group
值为CourseId
1 的视图,离开值为 0 的视图
可能是什么原因?