在Asp.net MVC視圖中,我創建了一個帶有輸入字段的表單。Asp.net MVC - 表單不發送給控制器
用戶設置名字(或其中的一部分),按下提交按鈕。
這是形式部分:
<div>
<form action="SearchCustomer" methos="post">
Enter first name: <input id="Text1" name="txtFirstName" type="text" />
<br />
<input id="Submit1" type="submit" value="Search Customer" />
</form>
</div>
這是SearchCustomer在控制器,從所述表格獲取數據:
CustomerDal dal = new CustomerDal();
string searchValue = Request.Form["txtFirstName"].ToString();
List<Customer> customers = (from x in dal.Customers
where x.FirstName.Contains(searchValue)
select x).ToList<Customer>();
CustomerModelView customerModelView = new CustomerModelView();
customerModelView.Customers = customers;
return View("ShowSearch", customerModelView);
當運行該程序,並進入第一名稱(例如「Jhon」),代碼返回到SearchCustomer函數,但Request.Form爲空。
爲什麼?
謝謝。
錯字!..而不是'methos = 「POST」'應該是'方法= 「郵報」' –
並且在表單動作不動作叫什麼名字? –
由於@KartikeyaKhosla提到,你有一個錯誤的'methos'應該是方法,並且你的動作應該採用以下格式:YourControllerName/YourActionName –