【发布时间】:2020-07-28 00:59:03
【问题描述】:
我还是 ASP.NET MVC 的初学者。我有一个项目,我现在正在使用两个视图和 1 个控制器。 1 个扫描页面、1 个数据输入页面和 1 个名为 LprController 的控制器。
所以在数据输入 cshtml 上,我有一个按钮,我试图从中获取数据,名为 lotnoTBX。
div class="col-md-4 col-sm-offset-3">
<img src="~/Images/Capture.PNG" class="media-object center-block"/>
<div class="block-main col-sm-8 col-sm-offset-4">
<h2>Scan Lot</h2>
<input id="lotnoTBX"/>
<div class="container-fluid row">
<button id="enterBtn" type="submit" class="btn btn-primary btn-group-lg" style="margin-top:5px;" onclick="location.href='@Url.Action("DataEntry", "Lpr")'">Enter</button>
</div>
</div>
</div>
然后在控制器页面上事情有点混乱。我不确定在哪里保存或如何保存 lotnoTBX 数据。基本上,我使用网络服务从文本框的结果中获取查询,并使用模型将其发布到数据输入页面。
public ActionResult ScanPage(FormCollection form)
{
string lotno = form["lotnoTBX"];
Session["lotno"] = lotno;
return View();
}
public ActionResult DataEntry()
{
FCoai.FCWCFT.PCSInterfaceClient client = new FCWCFT.PCSInterfaceClient("BasicHttpBinding_IPCSInterface1");
FCoai.FCWCFT.PCSResult x = client.getCurrentLotDetail(Session["lotno"].ToString());
return View();
}
然后这是我试图在 cshtml 中发布模型的数据输入页面。
<table>
<thead>
<tr>
<th class="table-active">OP</th>
<th class="table-active">Lotno</th>
<th class="table-active">Itemcode</th>
<th class="table-active">Marking</th>
<th class="table-active">Output</th>
</tr>
<tr>
<td @Model.op></td>
<td @Model.lotno></td>
<td @Model.itemCode></td>
<td @Model.marking></td>
<td @Model.output></td>
</tr>
</thead>
</table>
*edit 我错过了一个可能让某些人感到困惑的操作结果 请帮忙。
【问题讨论】:
-
您需要创建一个模型类并将其传递给控制器方法。控制器方法应该有模型参数。此外,您还需要在 HTML 中使用
name属性而不仅仅是id。id属性不会导致发布数据。 -
谁能帮我解决这个问题,也许有一个例子。抱歉,在提交输入 btn 后,我什至无法返回文本框值。
标签: c# asp.net-mvc