Hi, i have the following entities:
public class Category
{
public virtual int CategoryID { get; set; }
[Required(ErrorMessage = "Section is required")]
public virtual Section Section { get; set; }
[Required(ErrorMessage = "Category Name is required")]
public virtual string CategoryName { get; set; }
}
public class Section
{
public virtual int SectionID { get; set; }
public virtual string SectionName { get; set; }
}
Now within my add category view i have a textbox to enter the SectionID eg:
<%= Html.TextBoxFor(m => m.Section.SectionID) %>
I'd like to create a custom model binder to have the following logic:
If the model key ends with ID and has a value (a value was inserted into the textbox) then set the parent object (Section in this example) to Section.GetById(value entered) else set the parent object to null.
I'd really appreciate the help here as this has been baffling me for a while. Thanks