表单绑定给出空属性

Form binding giving null properties

我已经尝试了几种方法来解决问题,例如

默认活页夹问题:

而且他们都没有工作... 这显然也没有嵌套。其中大部分是由嵌套问题引起的...

Form.Request 正在获取提交的参数。只是模型似乎没有分配:s

更奇怪的是,该字段被标记为必填。但是模型状态也返回为有效。

我真的看不出我能找到或做更多...谢谢。

我的模型看起来像这样
EmailSubmitModel.cs

using System.ComponentModel.DataAnnotations;

namespace myapp.Models.Home
{
    public class EmailSubmitModel
    {
        [Required(ErrorMessage = "Please enter your name")]
        public string FriendName;
    }
}

HomeController.cs

using myapp.Models.Home;

[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Submit(EmailSubmitModel emailSubmitModel)
{
    if (ModelState.IsValid)
    {
        return Json(emailSubmitModel);
    }
    return View(emailSubmitModel);
}

index.cshtml

@using myapp.Models.Home
@model EmailSubmitModel
<form asp-controller="Home" asp-action="Submit" method="post">
    <div asp-validation-summary="All"></div>
    <label asp-for="FriendName">@Localizer["Friend's Name"]</label>
    <input asp-for="FriendName" type="text" />
    <span asp-validation-for="FriendName"></span>
    <input type="submit" class="btn btn-warning">@Localizer["Send the email"]</button>
</form>

FriendName 应声明为 property。当前是一个字段:

public string FriendName { get; set; }