I am using MVC3 with Entity Framework Code First. I have the following model.
public class MyObject
{
public int Id { get; set; }
public string Name { get; set; }
public int MySubObjectId { get; set; }
public virtual MySubObject MySubObject { get; set; }
}
public class MySubObject
{
public int Id { get; set; }
public string SubName { get; set; }
}
On my create page for MyObject, the user can either select an existing MySubObject to use, or create a new one (select or create is done w/ auto complete textbox in an edit template for MySubObject).
What is the proper way to handle this from a binding/controller perspective.
Should I use MySubObject.Id and create a new object if that Id is not valid? Should I just use the MySubObject.SubName and look up the Id when it gets posted back to the controller?
Everything I've come up with seems pretty messy on the controller side.