没有在MVC中遇到控制器

时间:2017-07-04 18:38:31

标签: asp.net-mvc

在我提交的登录表单中弹出窗口时,即使我使用post方法在beginform中提供了代码,也不会触及控制器。我需要将用户名和密码发送给我的控制器进行验证。无法弄清楚它为什么没有击中。

[HttpPost]
    public ActionResult LoginUser(UserInfo objUser)
    {

        int res = udaObj.CheckUser(objUser.UserName, objUser.Password);
        if (res >= 1)
        {
           return RedirectToAction("Appointment", "Home");
        }           
        else
        {
            //For testing purpose
            return RedirectToAction("Appointment", "Home");
        }
    }

我的观点如下:

 @using (Html.BeginForm("LoginUser", "Home", FormMethod.Post, new { id = "loginForm" }))
                {
                    <div class="tab-pane fade active in" id="signin">
                        <fieldset>
                            <!-- Sign In Form -->
                            <!-- Text input-->
                            <div class="control-group">
                                <label class="control-label" for="userid">Alias:</label>
                                <div class="controls">
                                   @* <input required="" id="userid" name="userid" type="text" class="form-control" placeholder="JoeSixpack" class="input-medium" required="">*@
                                     @Html.TextBoxFor(x => x.UserName, new { @class = "form-control input-large", @placeholder = "Joek@irawath.com", @required = "" , @id="userid" })
                                </div>
                            </div>

                            <!-- Password input-->
                            <div class="control-group">
                                <label class="control-label" for="passwordinput">Password:</label>
                                <div class="controls">
                                    @*<input required="" id="passwordinput" name="passwordinput" class="form-control" type="password" placeholder="********" class="input-medium">*@
                                     @Html.TextBoxFor(x => x.Password, new { @class = "form-control input-large", @placeholder = "********", @required = "", @type = "password" , @id="passwordinput" })
                                </div>
                            </div>

                            <!-- Multiple Checkboxes (inline) -->
                            <div class="control-group">
                                <label class="control-label" for="rememberme"></label>
                                <div class="controls">
                                    <label class="checkbox inline" for="rememberme-0">
                                        <input type="checkbox" name="rememberme" id="rememberme-0" value="Remember me" style="margin-left: 0px">
                                        Remember me
                                    </label>
                                </div>
                            </div>
                            <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>
                            <!-- Button -->
                            <div class="control-group">
                                <label class="control-label" for="signin"></label>
                                <div class="controls">
                                    @* <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>*@
                                </div>
                            </div>
                        </fieldset>
                    </div>
                }

1 个答案:

答案 0 :(得分:0)

检查对象UserInfo是否与您在视图中使用的模型相同。请尝试使用FormCollection并检查。