我正在尝试从我的 html 代码中获取数据,例如“acquingCode”、“cardAcceptor”和“merchantId”。我不知道如何在我的控制器中获取该数据。我知道它的 request.form。我相信我做错了。有没有更简单的方法可以通过函数将对象或每个名称作为参数传递?
html
<script type="text/javascript">
$(document).ready(function () {
$("#SavetreventLocationLookupAddButton").click(function () {
$("#addSaveTreventLocationLookup").submit();
});
});
添加 Trevent 位置查找
<form id="addSaveTreventLocationLookup" method="post" action="<%: Url.Action("AddSaveTreventLocationLookup","Prod") %>">
<table>
<tr>
<td colspan="3" class="tableHeader">Trevent Location Lookup Detail</td>
</tr>
<tr>
<td colspan="2" class="label">Acquiring Institution Identification Code:</td>
<td class="content">
<input type="text" maxlength="200" name="AcquiringInstitutionIdentificationCode" id="AcquiringInstitutionIdentificationCode" />
</td>
</tr>
<tr>
<td colspan="2" class="label">Card Acceptor Identification Code:</td>
<td class="content">
<input type="text" maxlength="200" name="CardAcceptorIdentificationCode" id="CardAcceptorIdentificationCode" />
</td>
</tr>
<tr>
<td colspan="2" class="label">Merchant Id:</td>
<td class="content">
<input type="text" maxlength="200" name="MerchantId" id="MerchantId" />
</td>
</tr>
<tr>
<td colspan="3" class="tableFooter">
<br />
<a id ="SavetreventLocationLookupAddButton" href="#" class="regularButton">Add</a>
<a href="javascript:history.back()" class="regularButton">Cancel</a>
</td>
</tr>
</table>
</form>
控制器
[HttpPost]
[AuthorizeAttribute(AdminRoles = "AddTreventLocationLookup")]
public ActionResult AddSaveTreventLocationLookup()
{
try
{
string acquiringInstitutionIdentificationCode; //= Request.Form["AcquiringInstitutionIdentificationCode"] ?? string.Empty;
string cardAcceptorIdentificationCode;// =/Request["CardAcceptorIdentificationCode"] ?? string.Empty;
string merchantId;// = Request["MerchantID"] ?? string.Empty;
if (!string.IsNullOrEmpty(Request.Form["AcquiringInstitutionIdentificationCode"]))
{
acquiringInstitutionIdentificationCode = Request.Form["AcquiringInstitutionIdentificationCode"];
}
if (!string.IsNullOrEmpty(Request.Form["CardAcceptorIdentificationCode"]))
{
cardAcceptorIdentificationCode = Request.Form["CardAcceptorIdentificationCode"];
}
if (!string.IsNullOrEmpty(Request.Form["MerchantID"]))
{
merchantId = Request.Form["MerchantID"];
}
AdminProductionServices.TreventLocationLookup treventLocationLookup = Administrator.Models.AdminProduction.TreventLocationLookup.loadTreventLocationLookup(Guid.Empty, Guid.Empty, string.Empty, string.Empty, string.Empty)[0];
treventLocationLookup.acquiringInstitutionIdentifcationCode = acquiringInstitutionIdentificationCode;
treventLocationLookup.cardAcceptorIdentificationCode = cardAcceptorIdentificationCode;
treventLocationLookup.merchantId = merchantId;
Administrator.Models.AdminProduction.TreventLocationLookup.addTreventLocationLookup(treventLocationLookup);
}
catch(Exception e)
{
Commons.ErrorHandling.ReportError("Administrator.Controller.ProdController AddSaveTreventLocationLookup()", e);
}
return RedirectToAction("SearchTreventLocationLookup", "Prod");
}