[HttpPost]
public ActionResult Orders1(IEnumerable<int> order)
{
using (CostcoEntities1 context = new CostcoEntities1())
{
var query = string.Empty;
foreach (var orderID in order)
{
query = (from a in context.CM_Checkout_Details
where a.CheckoutDetails_ID == orderID
select a).ToString();
}
return View(query);
}
}
这就是我的控制器的样子.. 我试图在文本框中读取两个数字(Id)并根据这些ID显示数据。
@using (Html.BeginForm("Orders1", "Track", FormMethod.Post))
{
@Html.TextBox("order")<br />
@Html.TextBox("order")
<input type="submit" value="Submit" />
}
答案 0 :(得分:0)
首先,更改文本框的名称,使它们不相同:
@using (Html.BeginForm("Orders1", "Track", FormMethod.Post))
{
@Html.TextBox("order1")<br />
@Html.TextBox("order2")
<input type="submit" value="Submit" />
}
接下来,更改操作方法的签名:
[HttpPost]
public ActionResult Orders1(string order1, string order2)
MVC的模型绑定将尝试将order1和order2匹配到Request.Form中的东西,例如,它应该拾取文本框值。