我正在尝试发布表单数据以提供服务 我的帖子回复
它正在服务中击中方法,但问题在于获取数据。任何人都可以建议一种检索数据的方法。
这是客户端的类
- 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();
}
我很困惑在方法中放什么?任何帮助
你需要使用 JsonResult 作为你的返回类型
[HttpPost]
public JsonResult CreateTravelRequest(TravelRequest travelDetail)
{
return Json(travelDetail, JsonRequestBehavior.AllowGet);
}