没有获取对象值或formcollection值 [英] Not getting the object values or formcollection values
问题描述
我正在尝试在MVC中验证用户的登录验证.我使用了一个弹出窗口,在该弹出窗口中,两种形式都显示为1(用于登录)和一种(用于注册).我无法获得用户输入的对象值或文本框值(用户名和密码),即使它碰到了控制器.
I'm trying to verify user's login verification in MVC. I used a pop-up where it displays two forms as 1 for login and one for Register. I'm unable to get the object values or text box values of user inputs(username & password) even though its hitting the controller.
[HttpPost]
public ActionResult CheckUser(UserInfo obj)
{
int res = udaObj.CheckUser(obj.UserName, obj.Password);
if (res >= 1)
{
return RedirectToAction("Appointment", "Home");
}
else
{
//For testing purpose
return RedirectToAction("Appointment", "Home");
}
}
我的cshtml如下:
My cshtml is as follows :
@using (Html.BeginForm("RegisterUser", "Home", FormMethod.Post, new { id = "regForm" }))
{
<div class="tab-pane fade" id="signup">
<fieldset>
<!-- Sign Up Form -->
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="Email">Email:</label>
<div class="controls">
@Html.TextBoxFor(x => x.Email, new { @class = "form-control input-large", @placeholder = "Joek@irawath.com", @required = "" })
</div>
</div>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="userid">Alias:</label>
<div class="controls">
@Html.TextBoxFor(x => x.UserName, new { @class = "form-control input-large", @placeholder = "Joek@irawath.com", @required = "" })
</div>
</div>
<!-- Password input-->
<div class="control-group">
<label class="control-label" for="password">Password:</label>
<div class="controls">
@Html.TextBoxFor(x => x.Password, new { @class = "form-control input-large", @placeholder = "********", @required = "", @type = "password" })
<em>1-8 Characters</em>
</div>
</div>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="reenterpassword">Re-Enter Password:</label>
<div class="controls">
<input id="reenterpassword" class="form-control" name="reenterpassword" type="password" placeholder="********" class="input-large" required="">
</div>
</div>
<!-- Button -->
<div class="control-group">
<label class="control-label" for="confirmsignup"></label>
<div class="controls">
<button id="btnconfirmsignup" type="submit" name="signin" class="btn btn-success">Sign Up</button>
@* <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>*@
</div>
</div>
</fieldset>
</div>
}
@using (Html.BeginForm("CheckUser", "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 = "" })
</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" })
</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>
<div class="control-group">
<label class="control-label" for="confirmsignup"></label>
<div class="controls">
<button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>
@* <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>*@
</div>
</div>
</fieldset>
</div>
}
UserInfo.cs
UserInfo.cs
public class UserInfo
{
public int UserId { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public bool Gender { get; set; }
public DateTime? Dob { get; set; }
public string PhNumber { get; set; }
public string ImagePath { get; set; }
public DateTime? RegDate { get; set; }
public string Email { get; set; }
}
推荐答案
我看不到您的代码有什么问题.
I do not see anything wrong with your code.
但是我可以猜测的是,您的控制器未遵循控制器的命名约定.您的控制器名称应带有"Controller"后缀.
But what I can guess is that your controller does not follow the naming convention of controllers. Your controller name should have a "Controller" suffix.
您的情况应该是
public class HomeController : Controller
{
....
}
让我知道是否有帮助
这篇关于没有获取对象值或formcollection值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!