Frage

I'm working in asp.net mvc 4. I have a login model with 2 required fields: email and password. I'm using @Html.TextboxFor to get the correct value back. This works for my password, but I can't seem to get it working for the account.

Here's my code:

.cshtml

@model IntraNoviUserLoginModel
@using (Html.BeginForm("Login", "Home"))
{
    @Html.TextBoxFor(m => m.Email)
    @Html.TextBoxFor(m => m.Password, new { id = "password", type = "password" })
}

Controller:

[HttpPost]
public ActionResult Login(IntraNoviUserLoginModel model)
{
    if (ModelState.IsValid)
    {
        //Code
    }
}

Model:

public class IntraNoviUserLoginModel
{
    [Required]
    public string Email { get; set; }

    [Required]
    [DataType(DataType.Password)]
    public string Password { get; set; }    
}

I have not set the email textbox to enabled=false. It should remain enabled the entire time.

I hope we can figure this out together

War es hilfreich?

Lösung

I fixed this by using EditorFor instead of TextboxFor. I don't know why it suddenly works, maybe somebody can enlighten me in the comments?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top