为什么 ActionResult 方法不从 Html.BeginForm() inside view 中获取任何参数?

Why ActionResult method doesn't take any parameter from Html.BeginForm() inside view?

我尝试创建一个名为 PersonalJobManagement 的数据库,其中包含我员工的信息。 我想编写一个 ASP.NET MVC 网站来为该数据库编辑、删除或创建新数据。

但问题是: 我编写创建视图,输入名称或 ID 等参数,但参数未处理到数据库中。已经加了8个员工,第9个不能加了

我在控制器中的创建方法:

public ActionResult Create()
{
     return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Person model)
{
     db.Person.Add(model);
     db.SaveChanges();
     return RedirectToAction("List");
}

我的创建视图:

       @using (Html.BeginForm())
       {
           @Html.AntiForgeryToken()
           <div>
               <div>
                   <b>Name</b>
                   <div>
                       @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new {} })
                       @Html.ValidationMessageFor(model => model.FirstName, "", new {})
                   </div>
               </div>
               <div>
                   <div>
                       <input type="submit" value="Save it"/>
                   </div>
               </div>
           </div>
       }

还有我的人物模型:

public partial class Person
   {
       public int BusinessEntityID { get; set; }
       public string PersonType { get; set; }
       public string Title { get; set; }
       public string FirstName { get; set; }
       public string MiddleName { get; set; }
       public string LastName { get; set; }
       public System.DateTime ModifiedDate { get; set; }
   
       public virtual BusinessEntity BusinessEntity { get; set; }
   }

搞定了! 我的 ~/Views/Shared/_Layout.cshtml 文件有一个表单标签,我不知道为什么,但在调用 POST 方法时会导致错误。所以如果你在这里,小心点