我正在尝试将表单数据发布到服务My Post Response From Client
它正在使用该方法,但问题在于获取数据。 任何人都建议使用一种方法来检索数据。
这是客户端的课程
- export class TravelRequestDetails
{
public InitiatorName:string;
public EmployeeName:string;
public IntiatedDate:Date;
public ProjectName:string;
public PurposeOfTravel:string;
public TravelFrom:string;
public TravelTo:string;
public StartDate:Date;
public EndDate:Date;
}
这是我在服务方面的课程
[JsonObject(MemberSerialization.OptIn)]
public class TravelRequest
{
[JsonProperty("InitiatorName")]
public string InitiatorName { get; set; }
[JsonProperty("EmployeeName")]
public string EmployeeName { get; set; }
[JsonProperty("IntiatedDate")]
public DateTime InitiatedDate { get; set; }
[JsonProperty("ProjectName")]
public string ProjectName { get; set; }
[JsonProperty("TravelFrom")]
public string TravelFrom { get; set; }
[JsonProperty("TravelTo")]
public string TravelTo { get; set; }
[JsonProperty("StartDate")]
public Nullable<DateTime> StartDate { get; set; }
[JsonProperty("EndDate")]
public Nullable<DateTime> EndDate { get; set; }
[JsonProperty("PurposeOfTravel")]
public string PurposeOfTravel { get; set; }
}
和服务方法
[Route("api/CreateRequest")]
[HttpPost]
public void CreateTravelRequest(TravelRequest travelDetail)
{
//travelDetail = Newtonsoft.Json.JsonConvert.DeserializeObject<TravelRequest>(Convert.ToString(travelDetail));
//// _travelRepository.CreateTravelRequest(travelDetail);
//return Ok();
}
我很困惑在方法中放什么?任何帮助
答案 0 :(得分:0)
您需要使用JsonResult作为返回类型
[HttpPost]
public JsonResult CreateTravelRequest(TravelRequest travelDetail)
{
return Json(travelDetail, JsonRequestBehavior.AllowGet);
}