0

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 Commented Jul 13, 2019 at 17:29

1 Answer 1

0

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) {

}

Sign up to request clarification or add additional context in comments.

Comments

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.