Well I want to pass two parameters using Json to the controller, where i use a query to get result....
Now I manage to pass one parameter(first one) but the second just wont work, if i did Price/4 is will work but adding /2 says 404 in console...
//Passing ID 4 and ID 3 to HomeController/Price
$(document).ready(function () {
$("#type, #States").change(function () {
$.getJSON('/Home/Price/4/2', function (data) {
var items = '<option>Select a State</option>';
$.each(data, function (i, state) {
items += "<option value='" + state.Value + "'>" + state.Text +"</option>";
});
$("#Price").html(items);
});
});
});
//Home Controller Function
public JsonResult States(int id, int ids)
{
using (TalyllynContext db = new TalyllynContext())
{
var query = from F in db.Fares
join p in db.TicketPreferences on
F.TicketPreferenceID equals p.ID
where F.TicketTypeID == id &&
F.TicketPreferenceID == ids
select p;
return Json(new SelectList(query.ToList(), "ID", "Name"),
JsonRequestBehavior.AllowGet);
}
}
Any more just let me know....
/Home/Price/{id}/{ids}? Or you can use$.getJSON('/Home/Price', { id: 4, ids: 2 }, function ....ToList()or creating aSelectListjust usevar query = from ...select p => new { Value = p.ID, Name = p.Name }); return Json(query, JsonRequestBehavior.AllowGet);