在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 –