MVC 3 Remote Confirmation Field Has a Complex Name

I have an input

@Html.TextBoxFor(m => m.Buyer.Email, new { @maxlength = "100" })

I want to check it with a remote attribute

[Remote("IsUserNameAvailable", "Validation")]        
public string Email { get; set; }

There is an action in the validation controller:

[HttpPost]
public JsonResult IsUserNameAvailable(string Email)

But of course, I get a null value in the email parameter. What parameter name should I pass to the IsUserNameAvailable method?

Update: I just looked at the request that is sent to the remote verification action: http: // myhost / Validation / IsUserNameAvailable?Buyer.Email=test@test.test The parameter name is Buyer.Email, how can I pass it to the function?

+5
source share
3 answers

HttpPost HttpGet. . . -, , IsUserNameAvailable, , JSON .

[HttpGet]
public JsonResult IsUserNameAvailable(string Email)
{
    // Do something
    if (your_email_check_returns_true)
    {
        return Json(true, JsonRequestBehavior.AllowGet);
    }

    return Json(false, JsonRequestBehavior.AllowGet);
}
0

"Buyer.email", ... , "" ModelBinder ?

0

Try changing the signature of your action to enable the binding prefix:

public JsonResult IsUserNameAvailable([Bind (Prefix="Buyer.") ] string Email)
0
source

All Articles