数据实体
- public class LoginModel
- {
- public LoginModel()
- {
- LoginName = HttpContext.Current.User.Identity.Name;
- }
- [Required]
- [DisplayName("用户名:")]
- public string LoginName
- { get; set; }
- [Required]
- [DataType(DataType.Password)]
- [DisplayName("密码:")]
- public string Password
- { get; set; }
- /// <summary>
- /// 用户验证结果
- /// </summary>
- public string ValidateResult
- { get; set; }
- }
页面上使用Html.LabelFor:
- <table width="460" border="0" align="center" >
- <tr>
- <td>
- </td>
- <td width="52">
- <%: Html.LabelFor(m => m.LoginName) %>
- </td>
- <td width="187">
- <%: Html.TextBoxFor(m => m.LoginName) %>
- </td>
- </tr>
- <tr>
- <td>
- </td>
- <td>
- <%: Html.LabelFor(m => m.Password) %>
- </td>
- <td>
- <%: Html.TextBoxFor(m => m.Password) %>
- </td>
- </tr>
- <tr>
- <td>
- </td>
- <td>
- </td>
- <td>
- <input type="submit" value="登 陆" style="width: 60px; background: url(../../../Content/Images/Button/btn57-21.jpg) no-repeat;
- border: none; color: #000;" />
- <input type="reset" value="取 消" style="width: 60px; background: url(../../../Content/Images/Button/btn57-21.jpg) no-repeat;
- border: none; color: #000;" />
- </td>
- </tr>
- ;/table>
运行效果:
LabelFor使用了页面的DisplayName属性