【发布时间】:2017-04-12 18:19:59
【问题描述】:
我正在构建一个网站,我需要显示一个客户列表。 When a customer is selected, to show his items, I send the id of the customer from the view with this:
<th>
@using (Html.BeginForm("SetID", "Client", FormMethod.Post, new
{ id = item.id.ToString() }))
{
@Html.Hidden("id", item.id.ToString());
<input type="submit" value="see items" />
}
</th>
我在控制器中收到 id 并将其保存以进行查询并以这种方式显示值。
private string customer_id
[HttpPost]
public ActionResult SetCustomer(string id) {
Save(id);
return RedirectToAction("Index");
}
private void Save(string id) {
this.customer_id = id;
}
但是当我被重定向到索引视图时,变量“customer_id”为空。我有什么遗漏吗?
【问题讨论】:
标签: c# asp.net-mvc-4 http-post