maciejka
maciejka

Reputation: 948

Put value into parameter in Html.BeginForm from input text

I have the Html.BeginForm

@using (Html.BeginForm("AddMeals", "ClientReservations",new { overallCost= $('#mealsOverallCost').value }))

I read from following input text.

<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>

Is there any way to get value from input filed and pass it into BeginForm. Presented by me way of reading.

overallCost= $('#mealsOverallCost').value

Is not proper.

Upvotes: 0

Views: 2574

Answers (1)

Shyju
Shyju

Reputation: 218962

You can create a hidden input form element with name attribute value "overallCost" and it will be available in the request body when you submit the form.

@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" />
}

Upvotes: 2

Related Questions