why do I always have so much trouble with the model binder?? I have the following controller:
namespace X.Web.Controllers
{
public class ExpertsVM
{
public string GivenName;
public string Surname;
}
public class AuthController : Controller
{
[HttpPost]
public ActionResult RegisterExpert(ExpertsVM v)
{
and my view looks like this:
@using X.Web.Controllers
@model ExpertsVM
@using (Html.BeginForm("RegisterExpert", "Auth"))
{
@Html.EditorFor(x => x.GivenName)
@Html.EditorFor(x => x.Surname)
so the form gets rendered like this:
<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="" />
but when the action gets invoked, v
contains all nulls. if I declare the action like this:
[HttpPost]
public ActionResult RegisterExpert(FormCollection f)
{
I see all the values... so what am I doing wrong here?
I'm not 100% sure but I would use property instead of public field.
try