0
votes

My webapi method couldn't accept string parameter.

In post method in webapi controller , i could get only an optional string parameter, but when i test my method without parameter it get following error:

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.String Get(Int32)' .

[HttpPost]
public IHttpActionResult List(string munZone="")
{ 

}
in route config:
          routes.MapRoute(
        name: "DefaultApi3",
        url: "api/{controller}/{action}"
      );
            routes.MapRoute(
    name: "DefaultApi2",
    url: "api/{controller}/{action}/{id}",
    defaults: new { id = UrlParameter.Optional }
  );

I need to send nullable string parameter instead of int id parameter

1
Show request url working & nonworking and why you are use List as action name ,use something else apart from keywords - Mangesh Auti

1 Answers

0
votes

I found it,if i send param as object of class, this problem will resolve.

public class T{ public string munZone }

[HttpPost] public IHttpActionResult List(T t) {

}