我有以下看法:
@using SuburbanCustPortal.SuburbanService
<br />
<br />
<table>
@if (ViewData["CustomerData"] != null)
{
foreach (var usr in (IEnumerable<CustomerData>) ViewData["CustomerData"])
{
using (Html.BeginForm("ShowCustomer2", "Customer", FormMethod.Post))
{
<tr>
@Html.HiddenFor(model => @usr.AccountId)
<td>
<input id="btn" type="submit" value="View"/>
</td>
<td>
@usr.Branch-@usr.AccountNumber
</td>
<td>
@usr.Name
</td>
<td>
@usr.DeliveryStreet
</td>
</tr>
}
}
}
</table>
<br />
我想获得单击按钮的 AccountId。它列出了该登录名上的所有帐户。
无论我如何引用它,我都会得到 null:
[HttpPost]
public ActionResult ShowCustomer2(FormCollection formCollection)
{
var corpid = MiscClasses.GetCookieInfo.TokenId;
var acctid = formCollection.Get("AccountId");
MiscClasses.GetCookieInfo.CurrentAccountGuid = acctid;
var sb = new StringBuilder();
sb.AppendLine("SuburbanCustPortal,Controllers.CustomerController.ExistingAccounts");
sb.AppendLine(string.Format("corpid: {0}", corpid));
sb.AppendLine(string.Format("acctid: {0}", acctid));
Logging.LogInfo(sb.ToString(), _asName);
var cr = new CustomerRequest();
cr.CompanyId = corpid;
cr.Account = acctid;
return View("AccountScreen", _client.GetCustomerByGuid(cr));
}
有人告诉我我做错了什么吗?
更新
我在视图中进行了以下更改:
@Html.Hidden(@usr.AccountId)
并作为:
@Html.Hidden(usr.AccountId)
我添加这些行只是为了验证控制器代码:
var acctid = formCollection["AccountId"];
acctid = formCollection.Get("AccountId");
两者仍然为空。