Click here to Skip to main content
14,449,405 members
Rate this:
Please Sign up or sign in to vote.
See more:

I have MVC architecture i want to give api to android developer .so how can i test the POST API services through POSTMAN.when i send post service through postman it will return null value..

What I have tried:


JSON DATA:- { "EmpFName":"Sa", "EmpMName":"s", "EmpLName":"SS", "AadhaarCardNumber":null, "PanCardNumber":null, "DateOfBirth":"1993-10-20T00:00:00", "Address":"Pune", "City":"Pune", "State":"Maharashtra", "Country":"India", "PinCode":"410505", "EmailID":"sa@GMAIL.COM", "Password":"123456", "PhotoPath":null, "MobileNo":"74487855545", "EmergancyContactNo":"7447774558", "MaritalStatus":"single", "Designation":"devlop", "ReportingMgr":1, "LeaveCount":18, "SpouseName":null, "SpDOB":null, "SpAge":null, "FirstChildName":null, "FCDOB":null, "FCAge":null, "SecondChidName":null, "SCDOB":null, "SCAge":null, "IsActive":true, "CreatedBy":null, "UpdatedOn":null, "Gender":"Female", "SCGender":"Male", "SpGender":"Female", "FCGender":"female"



[HttpPost] [Route("addemmployee")] public ActionResult AddEmployee( FormCollection form) { //employeedata empdata;

           Employee emp = new Employee();

           emp.JoiningDate = Convert.ToDateTime(form["joining_date"]);
               emp.EmpFName = form["txt_fname"];
               emp.EmpMName = form["txt_mname"];
               emp.EmpLName = form["txt_lname"];
               emp.AadhaarCardNumber = form["aadhaarnum"];

Updated 16-Mar-19 12:46pm
Afzaal Ahmad Zeeshan 15-Mar-19 9:12am
You are uploading JSON data, and expecting to read form-body? I don't think that's going to happen.

One thing that you can do is, use the Request.Form property to read the values from the HTTP request. If not, then try to parse the JSON to an object and then read the property to see if that helps.
Rate this:
Please Sign up or sign in to vote.

Solution 1

The properties enumerated in your JSON do not align with the form fields you are enumerating.

Have you tried this yet?
public ActionResult AddEmployee(employeedata empdata) {
  emp.EmpFName = empdata.EmpFName;
  // and so on
Member 12227707 16-Mar-19 0:51am
yes i try this but still it is not working..n how to JSON align with the form fields which are enumerating.
MadMyche 16-Mar-19 7:43am
What is the method that you are using to make this request?
Member 12227707 18-Mar-19 1:36am
There is mistake from my it's working.Thank u.
MadMyche 18-Mar-19 6:54am
Glad to hear you got it figured out
Rate this:
Please Sign up or sign in to vote.

Solution 2

Ok. Based on what you have posted here. The post with JSON in the body using PostMan will not work. because the Action is expecting FormCollection object. Here how I post the form data using Postman.

1. In Postman, Click On the Body
2. Click on form-data
3. Enter the key value

You also can click on the Bulk Edit link to paste in the key value in a batch. Here a screenshot of the Postman

postman_form-data.PNG (17.9 KB)

postman_form-data_MVC.PNG (8.2 KB)
Member 12227707 18-Mar-19 1:36am
it's working..thank u..but there is some values which are
divisiondetails.BranchId = LoggedInUser.BranchId;
divisiondetails.InstituteId = LoggedInUser.InstituteId;

after came debugger here it directly throw to pass these value through postman..
Bryian Tan 19-Mar-19 7:13am
How LoggedInUser get populated?
Member 12227707 20-Mar-19 0:11am
after login ..first authenticate then .

public ClientPortalIdentity LoggedInUser
return User.Identity as ClientPortalIdentity;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100