i have two models :-
public class Builder { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int BuilderId { get; set; } public string BuilderName { get; set; } }public class Project{ [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int ProjectId { get; set; } [Required] public string ProjectName { get; set; } [Required] public string Location { get; set; } [Required] public int BuilderId { get; set; } public Builder builder { get; set; }}When i am trying to post the builder class object from client side to the web api method, then it is reading the object from body. there is no problem in that. but when i am trying to add any Project with some Builder then it is not calling to desired method. and my Web Method :-
public HttpResponseMessage PostProject([FromUri] Project project) { if (ModelState.IsValid) { db.Projects.Add(project); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, project); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = project.ProjectId })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }my method to call the web api method :-
public async TaskAs per my knowledge, i think it is creating problem because my object is complex. I am new to Web API any suggestions from you are welcome. Please help.
ليست هناك تعليقات:
إرسال تعليق