I'm fairly new to ASP.NET MVC. The idea is very straightforward, but I can't seem to make it work.
I have a "ticket", which can be viewed under /Tickets/Details/[id]. Underneath this ticket is a list of comments and a "add comment" section. In the beginning I tested it all separately and manually wrote the TicketID. Now I need to save the current ticket's id and the whole ticket in this comment for later use. After the comment is successfully saved the page (of the ticket) should be refreshed.
Based on previous experience in ASP I tried this underneath my ticket details
<div class="panel panel-info">
<div class="panel-heading">Comments</div>
<div class="panel-body">
@{
Html.RenderAction("create", "TicketComments");
}
</div>
I tried the following thing in my TicketCommentsController.cs:
public ActionResult Create([Bind(Include = "ID, body")] TicketComment ticketComment)
{
Ticket ticket = db.Tickets.Find(ticketComment.ID);
if (ModelState.IsValid)
{
ticketComment.UserID = User.Identity.GetUserId();
ticketComment.AanmaakDateTime = DateTime.Now.ToLocalTime();
ticketComment.UpdateDateTime = DateTime.Now.ToLocalTime();
ticketComment.ParentTicketId = ticket.ID;
ticketComment.ParentTicket = ticket;
db.TicketComments.Add(ticketComment);
db.SaveChanges();
return View(ticket);
}
return View(ticket);
}
but on the return it gives me an excpetion:
"The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Ticket_5309A05301E0FE6AD5614FE3ED9E54D6FAB46DFEAFB2A38B4341FACD04441DF5', but this dictionary requires a model item of type 'Cronos.Models.TicketComment'."
I'm confused on what to do next. One thing I read was merge the TicketCommentsController in TicketsController, but this feels messy.
Can anyone help?