I have a shopping cart and I created a simple select list for quantity via Html
. I would like to use an Html.ActionLink
to get the value of that select list, however if I use JavaScript
in will not work as it is inside a PartialView
called product and there are multiple number of product on the page.
How could I get the value of that select list without JavaScript
? I did look around, but did not find anything useful. Is there any other way?
PartialView
<p>@Model.Description</p>
<p id="price">@Model.Price</p>
<p class="id hidden">@Model.GadgetID</p>
<select name="Select" id="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<p>
Html.ActionLink("Add To Cart", "AddOrder", "Home",new { qty = ?? , id = Model.GadgetID, price = Model.Price }, null )
</p>
Or if I use JavaScript
how can I get the right details as there are multiple products on the page.
View
that includes that PartialView
.
<div class="col-lg-10 products">
<div class="pad">
@foreach (var item in Model)
{
foreach (var gadget in item.Gadgets)
{
@Html.Partial("Gadget", gadget)
}
}
</div>
</div>
JQuery
<script type="text/javascript">
$(document).ready(function () {
$(".AddToCartBtn").click(function () {
var _qty = $(this).find("#quantity").val();
var _id = $(this).find(".id").val();
var _price = $("#price").html();
alert("qty: " + _qty + " id: " + _id + " price: " + _price);
});
});