im new in MVC,i want to bind my dropdown list when the page is loaded,for that I want to send my controller a flag to send me back the list I want for my drop down list,but the problem is when page loads,it does not send the flag,directly goes to controller
my view:
$(document).ready(function () {
var flg_parkList = "s";
debugger;
$.ajax({
dataType: "json",
type: "POST",
url: "@Url.Action("parkList","Ranking")",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "flg": flg_parkList }),
success: function (data) {
debugger;
}
});
$('#drplist')
.appendTo(container)
.kendoDropDownList({
dataSource: data,
dataTextField: "Text",
dataValueField: "Text",
valuePrimitive: true,
});
});
My controller:
public JsonResult parkList(string flg)
{
string useID = HttpContext.User.Identity.Name;
if (flg == "s")
{
var listOfParks = (from s in DB.MasterDatas
join m in DB.UsersTurbines
on s.turbine_id equals m.tur_id
where m.user_id == useID
select new SelectListItem
{
Text = s.turbine_windpark_name
}).ToList().Distinct();
return Json(listOfParks, JsonRequestBehavior.AllowGet);
}
else
return null;
}