0
这是我的cshtml文件。我想我在这里或在控制器中犯了一些错误,但不知道它是什么!无法发布登录的表单数据 - .NET MVC
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<div class="modal-body">
<div class="form-group">
<div>
@Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
</div>
<div>
@Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div>
@Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
</div>
<div>
@Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="modal-footer">
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Login" class="btn btn-default" />
</div>
</div>
}
这是控制器,目前我只是想接收发布数据后,将其重定向到另一页。但是它在发布/单击提交后再次调用Index()方法。
public class LandController : Controller
{
// GET: Land
private userDBcontext db = new userDBcontext();
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Login(User loginReq)
{
return this.RedirectToAction("Index", "Users");
}
}
您的剃须刀页面上是什么类型的模型? – krillgar
它的一个.cs类 – Pratik
显然,但数据不会发布的主要原因之一是因为您有不匹配的属性。幸运的是有人发现你错过了HTTP Verb,所以这是你的问题。 – krillgar