I have a nuget package which contains an MVC controller - MyController which has a method MethodWithStringParameter(string a)
and another method MethodWithoutParameters()
.
I have installed this nuget package in my MVC service and have registered the controller and the routes.
我有一个nuget包,其中包含一个MVC控制器 - MyController,它有一个方法MethodWithStringParameter(字符串a)和另一个方法MethodWithoutParameters()。我在我的MVC服务中安装了这个nuget包,并注册了控制器和路由。
public sealed class MyController : Controller
{
[System.Web.Mvc.HttpPost]
public HttpResponseMessage MethodWithStringParameter(string a)
{
return new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK
};
}
[System.Web.Mvc.HttpPost]
public HttpResponseMessage MethodWithoutParameters()
{
return new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK
};
}
}
When I try hitting MethodWithStringParameter
method, I get an exception
当我尝试点击MethodWithStringParameter方法时,我得到一个异常
Invalid JSON primitive: a.
无效的JSON原语:a。
However, I am able to hit the method MethodWithoutParameters
without any issues.
但是,我能够毫无问题地使用方法MethodWithoutParameters。
Detailed exception
Type: "System.ArgumentException"
Message: "Invalid JSON primitive: a."
消息:“无效的JSON原语:a。”
StackTrace: " at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) at System.Web.Mvc.JsonValueProviderFactory.GetValueProvider(ControllerContext controllerContext) at System.Web.Mvc.ValueProviderFactoryCollection.GetValueProvider(ControllerContext controllerContext) at System.Web.Mvc.ControllerBase.get_ValueProvider() at System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__19(AsyncCallback asyncCallback, Object asyncState)"
StackTrace:“System.Web上的System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject(),System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String输入,Int32)的System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32深度) System.Web.Mvc上System.Web.Mvc.JsonValueProviderFactory.GetValueProvider(ControllerContext controllerContext)的System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer序列化程序,字符串输入,类型类型,Int32 depthLimit)中的depthLimit,JavaScriptSerializer序列化程序) System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext)上的System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext,ParameterDescriptor parameterDescriptor)中的System.Web.Mvc.ControllerBase.get_ValueProvider()处的.ValueProviderFactoryCollection.GetValueProvider(ControllerContext controllerContext) ,ActionDescriptor actionDescriptor)在System.Web.Mvc.Async.AsyncControllerActionInvoker。<> c__DisplayClass21.b__19(AsyncCallback asyncCallback,Object asyncState)“
0
Have you tried posting empty body to this url http://domainname/My/MethodWithStringParameter?a=abcd
您是否尝试将空体发布到此URL http:// domainname / My / MethodWithStringParameter?a = abcd
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2014/12/12/d34661363dd6019353d445bc05d31749.html。