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