使用提琴手发布到网络 api 时模型为空(测试)
Model is null while POSTing to web api using fiddler (test)
您好,我的项目有以下模型 class。我试图在 Values Controller 的 WEB API POST 方法中获取表单值,但是收到的值为空。我来这里是为了获得您在 Form
中发布的有关获取值的建议
public class DetailModel
{
public string FirstName { get; set; }
public string MiddleName { get; set;}
public string LastName { get; set; }
public string Phone { get; set;}
public string Email { get; set; }
}
下面显示的是api控制器代码
public void Post([FromUri] DetailModel model)
{
try
{
SMTravelsEntities st = new SMTravelsEntities();
st.spTravelAPIDataCreation(model.FirstName, model.MiddleName, model.LastName, model.Phone, model.Email);
st.SaveChanges();
}
catch (Exception Ex)
{
throw Ex;
}
}
我已经尝试了 [FromBody] 和 [FromUri] 来接收模型数据。但是我在 "DetailModel".
中得到了空值
这是我的路线代码
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/",
defaults: new { id = RouteParameter.Optional }
);
我用fiddler测试过
{
"FirstName": "Sarath",
"MiddleName":"MM"
"LastName": "FF",
"Phone": "0000",
"Email":"s@s.com"
}
User-Agent: Fiddler
主持人:localhost:1194
内容长度:103
内容类型:application/json
这就是我为解决这个问题所做的。
public DetailModel Post([FromBody] DetailModel model)
{
try
{
SMTravelsEntities st = new SMTravelsEntities();
st.spTravelAPIDataCreation(model.candidateFirstName, model.candidateMiddleName, model.candidateLastName, model.candidatePhoneNumber, model.candEmail);
st.SaveChanges();
}
catch (Exception Ex)
{
throw Ex;
}
return model;
}
您好,我的项目有以下模型 class。我试图在 Values Controller 的 WEB API POST 方法中获取表单值,但是收到的值为空。我来这里是为了获得您在 Form
中发布的有关获取值的建议 public class DetailModel
{
public string FirstName { get; set; }
public string MiddleName { get; set;}
public string LastName { get; set; }
public string Phone { get; set;}
public string Email { get; set; }
}
下面显示的是api控制器代码
public void Post([FromUri] DetailModel model)
{
try
{
SMTravelsEntities st = new SMTravelsEntities();
st.spTravelAPIDataCreation(model.FirstName, model.MiddleName, model.LastName, model.Phone, model.Email);
st.SaveChanges();
}
catch (Exception Ex)
{
throw Ex;
}
}
我已经尝试了 [FromBody] 和 [FromUri] 来接收模型数据。但是我在 "DetailModel".
中得到了空值这是我的路线代码
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/",
defaults: new { id = RouteParameter.Optional }
);
我用fiddler测试过
{
"FirstName": "Sarath", "MiddleName":"MM" "LastName": "FF", "Phone": "0000", "Email":"s@s.com" }
User-Agent: Fiddler
主持人:localhost:1194 内容长度:103 内容类型:application/json
这就是我为解决这个问题所做的。
public DetailModel Post([FromBody] DetailModel model)
{
try
{
SMTravelsEntities st = new SMTravelsEntities();
st.spTravelAPIDataCreation(model.candidateFirstName, model.candidateMiddleName, model.candidateLastName, model.candidatePhoneNumber, model.candEmail);
st.SaveChanges();
}
catch (Exception Ex)
{
throw Ex;
}
return model;
}