通过邮递员发送时,POST控制器值始终为NULL:MVC CONTROLLER [英] POST controller value is always NULL while sending through postman:MVC CONTROLLER

查看:86
本文介绍了通过邮递员发送时,POST控制器值始终为NULL:MVC CONTROLLER的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 0 


我有MVC架构项目。现在我想给Android开发人员api。如何通过POSTMAN测试POST API服务。当我通过邮递员发送邮件服务时,它将返回空值..

我尝试过:

< pre> url:-http :// localhost / Master / AddEmployee

JSON数据: - {EmpFName:Sa,EmpMName:s,EmpLName:SS,AadhaarCardNumber:null ,PanCardNumber:null,DateOfBirth:1993-10-20T00:00:00,地址:浦那,城市:浦那,州:马哈拉施特拉邦,国家 :India,PinCode:410505,EmailID:sa@GMAIL.COM,密码: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,G ender:女,SCGender:男,SpGender:女,FCGender:女

}



 cODE: -  

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



尝试
{
员工emp =新员工();

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

MasterReposities.SaveEmployee(emp);

解决方案

JSON中枚举的属性与您枚举的表单字段不对齐。



你试过这个吗?

 [HttpPost] 
[路线( addemmployee)]
public ActionResult AddEmployee(employeedata empdata){
emp。 EmpFName = empdata.EmpFName;
// 依此类推


确定。根据您在此处发布的内容。使用 PostMan 在正文中使用 JSON 的帖子将无效。因为 Action 期待 FormCollection 对象。这里我如何使用Postman发布表单数据。



1.在Postman中,点击正文

2.点击表格 - 数据

3.输入键值



您还可以单击批量编辑链接以批量粘贴键值。这里是邮递员的截图



postman_form-data.PNG(17.9) KB)



postman_form-data_MVC.PNG(8.2 KB)

0


I have MVC architecture project.now 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:

<pre>url:-http://localhost/Master/AddEmployee

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"

}


cODE:-

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


try
           {
           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"];

             MasterReposities.SaveEmployee(emp);

解决方案

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

Have you tried this yet?

[HttpPost]
[Route("addemmployee")]
public ActionResult AddEmployee(employeedata empdata) {
  emp.EmpFName = empdata.EmpFName;
  // and so on


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)


这篇关于通过邮递员发送时,POST控制器值始终为NULL:MVC CONTROLLER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆