0

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.

1 Answer 1

2

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" />
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.