I have a view in my asp.net MVC 4 application which iterates through the model and shows a checkbox, a link and a button like this:
@foreach (var sv in Model)
{
@Html.CheckBox("VehicleId", false, new { value = sv.Id.ToString(), @id = "myCheckbox" + sv.Id.ToString() })
<a href="#">@sv.Mileage miles</a> - [email protected]
<button id="btnMakeOffer" class="btn btn-success btn-primary pull-right" data-toggle="modal" data-target="#article-editor" data-id="@sv.Id"><i class=" icon-shopping-cart icon-white"></i>Make an Offer</button><br />
}
The button should show bootstrap modal and all the information of model class. Right modal is shown because of data-target="#article-editor". I want to show modal only if checkbox is checked. So I wrote this jquery:
@section Scripts{
<script type="text/javascript">
$("#btnMakeOffer").on("click", function () {
if ($('#myCheckbox' + $(this).data('id')).is(':checked')) {
var vehicleId = $(this).data('id');
$.ajax({
url: "/Home/GetSearchCriteria",
type: "GET", //these is must
cache: false, //these is for IE
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { provinceId: 1 },
}).done(function (data) {
$("#Title").val(data.Title);
$("#Summary").val(data.Summary);
$("#Magazine").val(data.Magazine);
$("#Url").val(data.Url);
$("#PubMonth").val(data.Year.toString() + "-" +
("00" + data.Month.toString()).slice(-2));
$('#myModal').modal('show');
});
}
else {
alert('Record not selected!');
}
});
</script>
}
and action method
[GET("GetSearchCriteria")]
public ActionResult GetSearchCriteria(int id)
{
return Json(new { Title = "abc", Summary = "Summary", Magazine = "This is magazine", Url = "test url" }, JsonRequestBehavior.AllowGet);
}
but it is not hitting the action method. When i see in firefox console, it says:
Failed to load resource: the server responded with a status of 404 (Not Found) and url it shows is:
=1387802961520">http://localhost:27741/Home/GetSearchCriteria?provinceId=1&=1387802961520
not sure what is 1387802961520
Please suggest solution to this.
_character in your query string._=1387802961520. That value was because you setcachetofalse. Anyway, to fix your problem, changeprovinceIdto justiddata: { provinceId: 1 }todata: { id: 1 }