我有一個簡單的強類型視圖。必需屬性不能在asp.net工作mvc
@model GoldForGold.Models.LogonModel
@{
ViewBag.Title = "Logins";
Layout = "~/Views/Shared/_Layout.cshtml";
}
Logins
@using (Html.BeginForm()) {
Account Information
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName, new { id = "txtUserName" })
@Html.ValidationMessageFor(m => m.UserName)
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password, new { id = "txtPassword" })
@Html.ValidationMessageFor(m => m.Password)
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
<input type="submit" value="Log On" onclick="getcredentials()" />
}
模型代碼在這裏。
public class LogonModel
{
[Required(ErrorMessage="please enter username")]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
即使沒有輸入用戶名和密碼,我也看不到任何事情發生。
你能告訴我們您的Post操作方法。 – WannaCSharp