I want to call view using AJAX call with ASP.net MVC2.0 but it doesn’t work fine. This is an AJAX method
$.ajax({
type: 'POST',
url: '../Inventoryhealth/IHView?mac=' + val + '&name=' + val2 + '#fragment-3',
//url: '../Chart/CreateChart2?chartType=Column&a=null',
success: function (result) {
var res = result;
if (res != null && res == "1")
alert('System information can\'t be retrieved');
}
});
but if I use this it works fine
location.href = "../Inventoryhealth/IHView?mac=" + val + "&name=" + val2 + "#fragment-3";
This is view code
public ActionResult IHView(String mac, string name)
{
try
{
ViewData["PollTime"] = new ClientConfigurationService().getPollTime() * 60000;
SystemInventoryService sis = new SystemInventoryService();
SystemInformation systemInfo = new SystemInformation();
systemInfo = sis.getSystemInventory(mac);
systemInfo.ChartRefreshInterval = getInterval();
systemInfo.OName = name;
bool MoreCores = true;
if (Convert.ToInt16(systemInfo.NumberOfCores) < 2)
{
systemInfo.Core1UsageDetail = "0";
systemInfo.Core2UsageDetail = "0";
MoreCores = false;
}
Add(systemInfo.ProcessorLoadPercentage, systemInfo.MemoryTotalVirtualMemorySize, systemInfo.MemoryFreeVirtualMemory, systemInfo.DrivesSize, systemInfo.DrivesTotalFreeSpace, MoreCores, systemInfo.Core1UsageDetail, systemInfo.Core2UsageDetail);
var AC = new ActiveClient();
AC.ClientMac = mac;
if (db.ActiveClients.Count() > 0)
{
db.DeleteObject(db.ActiveClients.First());
}
db.AddToActiveClients(AC);
db.SaveChanges();
if (systemInfo != null)
{
return View(systemInfo);
}
else
{
// If Healh and status can't be retrieved
// Response.Redirect("../Inventoryhealth/InventoryIndex?error=1");
return Content("1");
}
}
Any idea?
I think instead of using Post, use Get method. There is no data option in the call so it means you don’t need posting. I hope it will work on changing Post to get.