表单提交与JS未提交到控制器



我想'张贴'与香草JS表单。还有其他类似的问题,但我不能让我的工作。数据没有传递给控制器。

我在页面上为用户提供了几个选项,显示为按钮。当用户单击一个按钮时,一个隐藏的表单被填充,然后JS将表单提交给控制器。

下面的隐藏表单:

[对于测试,我还没有"隐藏"表单字段,所以我可以监控正确的信息进入表单]

<form action="RetailTimePriceDisplayOne" method="post" id="postForm" name="postForm">
<input type="text" id="fmZero" value="@ViewBag.zero" />
<input type="text" id="fmVehicle" />
<input type="text" id="fmTeam" />
<input type="text" id="fmTLabor" />
<input type="text" id="fmRouteCost" />
<input type="text" id="fmRouteD" value="@ViewBag.vehicleMile"/>
<input type="text" id="fmRouteT" value="@ViewBag.vehicleTime"/>
</form>

我的JS:

<script>
function fillForm(vehicleType, teamCount, travelLabor, routeCost) {
document.getElementById("fmVehicle").value = vehicleType;
document.getElementById("fmTeam").value = teamCount;
var x = @ViewBag.rateTravelDrvr;
if (teamCount > 1) {
x = @ViewBag.rateTravelDrvr + (@ViewBag.rateTravelCrew * (teamCount - 1));
}
document.getElementById("fmTLabor").value = x;
var y;
if (vehicleType == "V") {
y = @ViewBag.vVPrice;
}
if (vehicleType == "H") {
y = @ViewBag.vHPrice;
}
if (vehicleType == "T") {
y = @ViewBag.vTPrice;
}
document.getElementById("fmRouteCost").value = y;
SubmitForm();
}
function SubmitForm() {
var myForm = document.getElementById('postForm');
//document.forms["postForm"].submit();
myForm.method = 'post';
myForm.submit();
}
</script>

正确填写了表单,但没有向控制器提交数据。你可以看到我稍微摆弄了一下。我的一个想法是,该方法将更改为"get",通过显式指定该方法,我可能会解决这个问题。但是没有这样的运气。谢谢!

编辑:按要求,页面上触发JS函数的6个按钮之一。

<button class="btn btn-secondary btn-lg" style="width:100%; height:100%;" onclick="fillForm('T',3)">
<strong>@ViewBag.TrkThr</strong>
<p>with 3 persons</p>
<p>+ @ViewBag.TrkMinute per labor minute*</p>
</button>

通常当我想提交表单时,我使用按钮,然后使用onClick事件

name"的输入没有定义,因此数据没有被发布。

最新更新