I am attempting to pass parameters from a Bootstrap modal popup to my controller using Javascript and Ajax. However, when I click the button, it does not seem to work on the controller. How can I successfully send these parameters?
Below is the HTML code for my modal:
<div class="modal fade" role="dialog" id="mymodal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal">×</button>
<label for="infoh" id="info" name="info"></label>
<input type="hidden" id="infoh" name="infoh" value="" />
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-3">
@Html.Label("Product : ")
</div>
<div class="col-md-3">
<input type="number" class="input-sm" id="product" name="product"/>
</div>
</div><br />
<div class="row">
<div class="col-md-3">
@Html.Label("Price : ")
</div>
<div class="col-md-3">
<input type="number" class="input-sm" id="price" name="price"/>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-success" id="change" onclick="func(this)" name="change">@Html.Label("change") </button>
</div>
</div>
</div>
The modal functions correctly. Here is the Javascript code:
@section Scripts{
<script type="text/javascript">
func(x) {
var pricee = document.getElementById("price").value;
var productt = document.getElementById("product").value;
var info = document.getElementById("infoh").value;
$.ajax({
url: 'myController/Action',
type: 'POST',
data: { 'info': info, 'price': pricee, 'product': productt },
success: function () {
alert("done");
}
});
}
</script>
}
and here is my Controller code, which does not seem to work or trigger:
[HttpPost]
public ActionResult Action(string info,double price,double product)
{
dbEntities updateaction = new dbEntities();
int id = (Convert.ToInt32(Session["id"]));
string myinfo = info;
Product pp= updateaction.Product.Where(m => m.database_id.Equals(id) && m.name.Equals(myinfo)).SingleOrDefault();
pp.price = price;
pp.product = product;
int i= updateaction.SaveChanges();
Session["warning"] = i;
return View();
}
I am using the Opera Browser and I am unable to set a breakpoint in my code.