Hi,
I am trying to call a Web Api method (/BSCSecurityAddressBookWeb/api/MultiJobChangeApi/Get) when a button clicked, it has to load a new page (MultiJobChange)
(from Employee page to MultiJobChange)
and in MultiJobChange.js file I have written code for calling the Web Api,
MultiJobChange.cshtml page is loading by calling its Controller using the call window.open('/BSCSecurityAddressBookWeb/MultiJobChange/', '_self', false);,
MultiJobChangeController Index method returns View, up loading of the cshtml page its working properly, but the call to /BSCSecurityAddressBookWeb/api/MultiJobChangeApi/Get is not going.
Can anybody please help me in this regards, I am new to MVC, I am able to move to the new Page or Controller from Employee Page as Employee Page (or Controller is starting one) but not able to call the Web Api method from there even though I am seeing all js files loaded in resources in browser debugger, but still the Web Api call is not making through. Any help would be every supportive thanks in advance.
My Code looks as below:
};
code in Employee.js file
loadEmployee: function (employeeID) {
$.get("/BSCSecurityAddressBookWeb/api/EmployeeAPI/Get").then(function (data) {
}
code in Layout.js file
$(function () {
$("#btnEmployee").click(function (event) {
Employee.loadEmployee();
window.open('/BSCSecurityAddressBookWeb/Employee/', '_self', false);
});
});
Code in MultiJobChange/Index.js file
function LoadMultiJobChange() {
MultiJobChange.loadMultiJobChange();
};
$(function () {
LoadMultiJobChange();
});
function LoadEmployee() {
Employee.loadEmployee();
};
$(function () {
LoadEmployee();
});
{
// GET: api/MultiJobChangeApi
public List<userlist> Get()
{
dynamic model = null;
using (AppDevSecEntities ctx = new AppDevSecEntities())
{
var temp = ctx.UserLists.AsNoTracking().OrderByDescending(x => x.LastName);
if (temp != null)
model = temp.ToList<userlist>();
}
return model;
}
}
public class MultiJobChangeController : Controller
{
// GET: MultiJobChange
public ActionResult Index()
{
using (AppDevSecEntities ctx = new AppDevSecEntities())
{
BSCCrystalReportsViewerEntities ctx2 = new BSCCrystalReportsViewerEntities();
}
return View();
}
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
I am trying to call a Web Api method (/BSCSecurityAddressBookWeb/api/MultiJobChangeApi/Get) when a button clicked, it has to load a new page (MultiJobChange)
(from Employee page to MultiJobChange)
and in MultiJobChange.js file I have written code for calling the Web Api,
MultiJobChange.cshtml page is loading by calling its Controller using the call window.open('/BSCSecurityAddressBookWeb/MultiJobChange/', '_self', false);,
MultiJobChangeController Index method returns View, up loading of the cshtml page its working properly, but the call to /BSCSecurityAddressBookWeb/api/MultiJobChangeApi/Get is not going.
Can anybody please help me in this regards, I am new to MVC, I am able to move to the new Page or Controller from Employee Page as Employee Page (or Controller is starting one) but not able to call the Web Api method from there even though I am seeing all js files loaded in resources in browser debugger, but still the Web Api call is not making through. Any help would be every supportive thanks in advance.
My Code looks as below:
code in MultiJobChange.js file MultiJobChange = { loadMultiJobChange: function (employeeID) { $.get("/BSCSecurityAddressBookWeb/api/MultiJobChangeApi/Get").then(function (data) { <pre> var list = $("#ddlEmployees"); var selectedValue = list.val(); list.empty(); $.each(data, function (index, userList) { $("<option>").attr("value", userList.EmployeeID).text(applicationgroup.LastName).appendTo(list); }); $("#btnClearList").click(function (event) { $("#lbxEmployees").empty(); }); $("#btnRemoveEmployee").click(function (event) { $("#lbxEmployees option:selected").remove(); }); }
};
code in Employee.js file
loadEmployee: function (employeeID) {
$.get("/BSCSecurityAddressBookWeb/api/EmployeeAPI/Get").then(function (data) {
var list = $("#ddlApplicationGroup"); var selectedValue = list.val(); list.empty(); $.each(data.ApplicationGroups, function (index, applicationgroup) { $("<option>").attr("value", applicationgroup.ApplicationGroupID).text(applicationgroup.ApplicationGroupName).appendTo(list); }); if ((selectedValue == null) || (selectedValue == undefined)) { list.prepend("<option value='-1' selected='selected'>Select value</option>"); if ((list[0] != undefined) && (list[0] != null)) list[0].selectedIndex = 0; } else { list.val(selectedValue); } var list = $("#ddlReportPack"); var selectedValue = list.val(); list.empty(); $.each(data.ReportPacks, function (index, reportpack) { $("<option>").attr("value", reportpack.ReportPackID).text(reportpack.ReportPackName).appendTo(list); }); if ((selectedValue == null) || (selectedValue == undefined)) { list.prepend("<option value='-1' selected='selected'>Select value</option>"); if ((list[0] != undefined) && (list[0] != null)) list[0].selectedIndex = 0; } else { list.val(selectedValue); } });
}
code in Layout.js file
$(function () {
$("#btnEmployee").click(function (event) {
Employee.loadEmployee();
window.open('/BSCSecurityAddressBookWeb/Employee/', '_self', false);
});
$("#btnMultiJobChange").click(function (event) { MultiJobChange.loadMultiJobChange(); window.open('/BSCSecurityAddressBookWeb/MultiJobChange/', '_self', false); });
});
Code in MultiJobChange/Index.js file
function LoadMultiJobChange() {
MultiJobChange.loadMultiJobChange();
};
$(function () {
LoadMultiJobChange();
});
Code in Employee/Index.js file
function LoadEmployee() {
Employee.loadEmployee();
};
$(function () {
LoadEmployee();
});
Controller methods:
publicclass MultiJobChangeApiController : ApiController
{
// GET: api/MultiJobChangeApi
public List<userlist> Get()
{
dynamic model = null;
using (AppDevSecEntities ctx = new AppDevSecEntities())
{
var temp = ctx.UserLists.AsNoTracking().OrderByDescending(x => x.LastName);
if (temp != null)
model = temp.ToList<userlist>();
}
return model;
}
}
public class MultiJobChangeController : Controller
{
// GET: MultiJobChange
public ActionResult Index()
{
using (AppDevSecEntities ctx = new AppDevSecEntities())
{
BSCCrystalReportsViewerEntities ctx2 = new BSCCrystalReportsViewerEntities();
}
return View();
}
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."