Timmer Timmer - 3 months ago 6
ASP.NET (C#) Question

MVC model not saving the value

var ticketnumber = TempData["ticketId"] as Ticket;
ticketnumber.TicketId = model.TicketId;
db.SaveChanges();
HttpPostedFileBase file = Request.Files["ImageData"];
UploadRepository service = new UploadRepository();
int i = service.UploadImageInDataBase(file, model);


I have the value inside my tempdata but when i try to assign the value of it to the model value it doesnt save and even in debug it tells me the value hasnt changed so i just dont get what i am doing wrong.

Answer

You need to change the assignment:

From:

ticketnumber.TicketId = model.TicketId;

To:

model.TicketId = ticketnumber.TicketId;
Comments