模型绑定器困境

ekk*_*kis 1 c# modelbinders razor asp.net-mvc-3

为什么我总是在模型绑定器上遇到这么多麻烦?我有以下控制器:

namespace X.Web.Controllers
{
    public class ExpertsVM
    {
        public string GivenName;
        public string Surname;
    }

    public class AuthController : Controller
    {
        [HttpPost]
        public ActionResult RegisterExpert(ExpertsVM v)
        {
Run Code Online (Sandbox Code Playgroud)

我的观点看起来像这样:

@using X.Web.Controllers
@model ExpertsVM

@using (Html.BeginForm("RegisterExpert", "Auth"))
{
    @Html.EditorFor(x => x.GivenName)
    @Html.EditorFor(x => x.Surname)
Run Code Online (Sandbox Code Playgroud)

所以表单呈现如下:

<form action="/Auth/RegisterExpert" method="post">
<input class="text-box single-line" id="GivenName" name="GivenName" type="text" value="" />
<input class="text-box single-line" id="Surname" name="Surname" type="text" value="" />
Run Code Online (Sandbox Code Playgroud)

但是当调用动作时,v包含所有空值.如果我宣布这样的行动:

[HttpPost]
public ActionResult RegisterExpert(FormCollection f)
{
Run Code Online (Sandbox Code Playgroud)

我看到了所有的价值......所以我在这里做错了什么?

Vde*_*edT 6

我不是100%肯定,但我会使用财产而不是公共领域.

尝试

public class ExpertsVM
{
    public string GivenName {get;set;}
    public string Surname {get;set;}
}
Run Code Online (Sandbox Code Playgroud)