I have a message board in ASP.Net MVC and when the user creates a new Post they must select a category, when I create a view (Create) the field (Categories) doesnt appear?
The database has a middle table MessageToCatRel which contains a messageID and a CatId. I think this is what is confusing MVC. At the moment i am doing the following, but dont like the idea of using the Request.Form. How can I get it to post back in the Object like the other fields?
public ActionResult Create(Message messageToCreate) //Post back from Message Post
{
if (!ModelState.IsValid)
{
this.LoadCategoryViewData();
return View();
}
//Now try and save this in the Database /
/And Save
IMessageRepository repo = new MessageRepository();
MessageCategory curCatRel = new MessageCategory();
curCatRel.CategoryID = Convert.ToInt32(Request.Form["Categories"]);
messageToCreate.MessageCategories.Add(curCatRel);
messageToCreate.CreatedBy = 1; //Temp messure
messageToCreate.PublishDateTime = DateTime.Now;
repo.AddMessage(messageToCreate);
repo.Save();