2

I have controller action which returns JsonResult and is consumed by jquery ajax get request. All works well on my well my dev machine but when copied on production hosting I get below exception on last line controller action:

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult Single(int UNIQUE_NO) {
  ...
  return Json(data, JsonRequestBehavior.AllowGet);  // < here exception is thrown
}

Method not found: 'System.Web.Mvc.JsonResult System.Web.Mvc.Controller.Json(System.Object, System.Web.Mvc.JsonRequestBehavior)'.

Exception is being captured by ELHAM.

Platform: ASP.NET MVC 2 Beta

Dlls included with app (Copy local : true): Microsoft.Web.Mvc, MvcContrib, MvcContrib.FluentHtml, MvcContrib.TestHelper, Rhino.Mocks, System.Web.Mvc, System.Web.Routing

What is going on here? What/Where should I be looking for this? (as mentioned above I dont get this exception on my dev machine where json result object is generated as expected and returned to caller)

Here is call stack (ELMAH):

System.MissingMethodException: Method not found: 'System.Web.Mvc.JsonResult System.Web.Mvc.Controller.Json(System.Object, System.Web.Mvc.JsonRequestBehavior)'. at NN_AccessToWeb_MVC2.Controllers.HomeController.Single(Int32 UNIQUE_NO) at lambda_method(ExecutionScope , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassa.b__7() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassa.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)

1
  • Did you ever find a solution to this? It's a very interesting exception you have there... Commented Dec 21, 2012 at 17:00

2 Answers 2

2

Try returning a new JsonResult:

return new JsonResult {
    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
    Data = /* you model goes here */,
    ContentType = "application/json",
    ContentEncoding = Encoding.UTF8
};
Sign up to request clarification or add additional context in comments.

5 Comments

Isnt Json(data, JsonRequestBehavior.AllowGet) already JsonResult ?
It is. It's a helper like View() is a helper for new'ing up a ViewResult. Perhaps you're not including the right namespaces?
That throws similar exception> System.MissingMethodException Method not found: 'Void System.Web.Mvc.JsonResult.set_JsonRequestBehavior(System.Web.Mvc.JsonRequestBehavior)'.< Which namespace(s) could I missing be missing ?
What namespaces are you including?
I've added included namespaces in original post. This is obviously issue with namespaces or similar as I cant recreate exception on dev machine.
0
return Json(data, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet);

1 Comment

return Json(YOURDATA), "application/json" ,Encoding.UTF8, JsonRequestBehavior.AllowGet); ITS WORK WOW

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.