控件器中很简单: public ActionResult Index()
        {
            return View();
        }
在Model中添加了一个类:public class UserLogin
    {
        [Required(ErrorMessage = "请输入用户账号")]
        public string UserId { get; set; }        [Required(ErrorMessage = "请输入密码")]
        public string UserPwd { get; set; }
    }
然后添加Index 页面视图@model EaiMngPlatform.Models.UserLogin
@{
    Layout = null;
    ViewBag.Title = "用户登陆";
}
<h2>用户登陆信息</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script><script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script> 
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>用户登陆</legend>
        <div class="editor-label">
            用户名
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserId)
            @Html.ValidationMessageFor(model => model.UserId)
        </div>
        <div class ="editor-label">
            密码
        </div>
        <div class="editor-field">
            @Html.EditorFor(mode => Model.UserPwd)
            @Html.ValidationMessageFor(model => model.UserPwd)
        </div>
        <p>
            <input type="submit" value="登陆" />
        </p>
    </fieldset>
}
<div>
    @Html.ActionLink("用户注册", "Index")
</div>只是想玩玩验证, 所以没有连数据库, 运行的时候, 点"登陆"按钮, 没有出现预想中的效果 ...没任何提示, 是哪里弄错了吗?

解决方案 »

  1.   

    该表单提交方式为POST,如下添加Control方法 [HttpPost]
            public ActionResult Register(RegisterModel model)
            {
                if (ModelState.IsValid)
                {
                    // 尝试注册用户
                    MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);                if (createStatus == MembershipCreateStatus.Success)
                    {
                        FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                    }
                }            // 如果我们进行到这一步时某个地方出错,则重新显示表单
                ViewBag.PasswordLength = MembershipService.MinPasswordLength;
                return View(model);
            }
      

  2.   

    http://developer.51cto.com/art/200903/117513.htm
      

  3.   


    首页就是显示一个登陆表单, 怎样添加这个[HttpPost]呢?
      

  4.   

    @using (Html.BeginForm()) {
    会默认解析为POST方式你在Control方法的上年加上[HttpPost]
    就可以,然后接受VIEW中的MODEL,然后验证判断ModelState.IsValid 表单是否通过验证
    [HttpPost]
    public ActionResult Register(RegisterModel model)
    {