我有Html.BeginForm
@using (Html.BeginForm("AddMeals", "ClientReservations",new { overallCost= $('#mealsOverallCost').value }))
我从以下输入文字中读到。
<div id="DivMealsOverallCost">
@Html.Label("Całkowity koszt", htmlAttributes: new { @class = "control-label col-md-2" })
<input type="text" id="mealsOverallCost" readonly="readonly" value="@ViewBag.OverallCost" />
</div>
有没有办法从输入字段获取值并将其传递给BeginForm。由我提供的阅读方式。
overallCost= $('#mealsOverallCost').value
不合适。
答案 0 :(得分:0)
您可以创建一个隐藏的输入表单元素,其名称属性值为&#34; overallCost&#34;当您提交表格时,它将在请求正文中提供。
@using (Html.BeginForm("AddMeals", "ClientReservations"))
{
<input type="text" id="mealsOverallCost" readonly="readonly"
value="@ViewBag.OverallCost" />
<input type="hidden" name="overallCost" value="@ViewBag.OverallCost" />
<input type="submit" />
}