neda Derakhshesh neda Derakhshesh - 6 months ago 16
jQuery Question

Bind Data Of a span to database with ASP MVC,Uses Model Binder

I'm new in MVC

I need some suggestions for how to make a counter then give the value of it to model binder.

I have two

modal the first one I have this counter for users to choose the number of their request it's like this :
when user click on plus icon the number changed
By Javascript

enter image description here

when user click on next button , the next modal page shows, which I have
number of travelers
there by javascript. and also a form which I want model binder to make an object of it.

here is the view of my next modal page in summary

<span id="selecteddate"></span>

<span id="selectedcount"></span>

<span id="selectedprice"></span>

and here is javascript :

$(".nextbtn").click(function () {

$("#selecteddate").html("Selected Date is : "+$("#showdate").html());
$("#selectedprice").html("Total Price is : " + $("#tpriceforall").html());

and it works correctly.

and also I have a Form in this next modal page too . I want to pass input data of users to data base + the number which is available in
java script set it each time

as I want to use
, there is an input which it would be hidden.
but just to pass data . here is the input for TravelersCount of my Request Model

<div class="form-group">
@Html.LabelFor(model => model.Request.TravelersCount, htmlAttributes: new {@class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Request.TravelersCount, new { htmlAttributes = new { @class = "form-control", @*@Value=?????*@ } })
@Html.ValidationMessageFor(model => model.Request.TravelersCount, "", new { @class = "text-danger" })

What Should I write for
in the

Or if this way is completely irregular please suggest me new one.
Really appreciate you'r help. thanks


Your EditorFor() method creates an input with id="Request_TravelersCount".

To update its value when the button is clicked, you can use

$(".nextbtn").click(function () {
    $("#selecteddate").html("Selected Date is : "+$("#showdate").html());
    $("#selectedprice").html("Total Price is : " + $("#tpriceforall").html());
    var num = $("#shownum").html();

Side note: You should not attempt to set the value attribute in a HtmlHelper method (the method will set the correct value taking into account ModelState values)