$.post always failed ASP.NET MVC with provider hosted app

101 Views Asked by At

I'm using following code in a SharePoint provider hosted MVC app to hit a controller method

var urlAddProduct = "/Home/AddProduct?SPHostUrl=" + spHostUrl;
$.post(urlAddProduct,
        {
          id: id            
        }).done(function () {

        }).fail(function () {
             alert("Failed to add the new product!");
 });
 //method
  [SharePointContextFilter]
 public ActionResult AddProduct(string id) {
    var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
    using(var clientContext = spContext.CreateUserClientContextForSPHost()) {
    }
  return View();
}

Code is working fine but always return in failed state/failed alert.I am not getting any code exception.

1

There are 1 best solutions below

4
On

According to your comment, check to see if you have a view in your solution under path /Views/Home/AddProduct.cshtml