2017-08-29 18 views
0

から私は、入力されたテキストを次の中からお読み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

あなたはname属性値「overallCost」との隠された入力フォーム要素を作成することができますし、フォームを送信する際には、リクエストボディで利用できるようになります。

@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" /> 
} 
関連する問題