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.
According to your comment, check to see if you have a view in your solution under path
/Views/Home/AddProduct.cshtml