register属性在视图模型中不起作用 [英] register attribute not working in view model

查看:71
本文介绍了register属性在视图模型中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的强类型视图。



@model GoldForGold.Models.LogonModel



@ {

ViewBag .Title =登录;

布局=〜/ Views / Shared / _Layout.cshtml;

}



登录





@using(Html.BeginForm()){

I have a simple "strongly typed view" .

@model GoldForGold.Models.LogonModel

@{
ViewBag.Title = "Logins";
Layout = "~/Views/Shared/_Layout.cshtml";
}

Logins



@using (Html.BeginForm()) {





账户信息





Account Information



@ Html.LabelFor(m => m.UserName)


@Html.LabelFor(m => m.UserName)






@ Html.TextBoxFor(m => m.UserName,new {id =txtUserName})

@ Html.ValidationMessageFor(m => ; m.UserName)


@Html.TextBoxFor(m => m.UserName, new { id = "txtUserName" })
@Html.ValidationMessageFor(m => m.UserName)









@ Html.LabelFor(m => m.Password)


@Html.LabelFor(m => m.Password)






@ Html.PasswordFor(m => m.Password,new {id =txtPassword})

@ Html.ValidationMessageFor(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; m.RememberMe)


@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)







< input type =submitvalue =登录onclick =getcredentials()/>




<input type="submit" value="Log On" onclick="getcredentials()" />



}



------ -----------------型号代码在这里----------------------------- ---------------






}

-----------------------Model code is here --------------------------------------------


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; }
   }











即使我没有输入用户名和密码,我也没有看到任何事情发生。我在这里遗漏了什么?感谢提前






I see nothing is happening even when i do not enter username and password. Am i missing something here?Thanks in Advance

推荐答案

你应该删除下一个代码new {id =txtUserName}和new {id =txtPassword你的@ Html.TextBoxFor()定义中的}和你的视图应该有效!
You should remove the next code "new { id = "txtUserName" }" and "new { id = "txtPassword" }" from your @Html.TextBoxFor() definition and your view should work!


这篇关于register属性在视图模型中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆