I have the following classes:
public class State
{
public long Id { get; set; }
public string Name { get; set; }
public string Abbreviation { get; set; }
// Navigation Properties
public virtual Country Country { get; set; }
}
public class School
{
public long Id { get; set; }
public string Name { get; set; }
public string Abbreviation { get; set; }
// Navigation Properties
public virtual State State { get; set; }
}
and the following data in my SQL Server
| School| | |
| Id | Name | State |
| 1 | UCLA | 1 |
+-------+-------------+---------------+
| State | | |
| Id | Name | Abbreviation |
| 1 | California | CA |
I'm attempting to create a Rest controller that creates an instance of school using the HTTP POST verb using Web API.
public HttpResponseMessage<School> Post( School school )
{
SchoolService.CreateSchool( school );
var response = new HttpResponseMessage<School>( school, HttpStatusCode.Created );
string uri = Url.Route( null, new { id = school.Id } );
response.Headers.Location = new Uri( Request.RequestUri, uri );
return response;
}
Web API properly binds my School class's Name and Abbreviation properties from my web form and calls the POST method in the controller, but it doesn't know what to do with the State class. I'm not quite sure how to set that up. I'd like to have a dropdown that is bound to the State class and when I submit the creation of the School, the correct state from my existing data will get assigned to the new school instance.
Storeclass? can you post the HTTP Request details (headers, form fields & values, etc.)?