2017-04-21 24 views
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"); 
    } 
} 
+0

您的剃鬚刀頁面上是什麼類型的模型? – krillgar

+0

它的一個.cs類 – Pratik

+0

顯然,但數據不會發布的主要原因之一是因爲您有不匹配的屬性。幸運的是有人發現你錯過了HTTP Verb,所以這是你的問題。 – krillgar

回答

1

你沒有指定表單的動作,因此它發佈到默認情況下,相應的頁面/動作(例如指數)。您可以嘗試將Html.BeginForm()更換爲Html.BeginForm("Login", "Land")並嘗試一下嗎?

有關使用的更多信息,請參見MSDN