Search code examples
model-view-controllerviewtransfer

MVC Transfer Data Between Views


I just started to learn MVC and am trying to understand how it works.

I don't want to send users to different views for all edit, insert and list operations.

In my sample application a View contains a list of items and below the list there is a form (for inserting new items) with action "{Controller}/Create" but there is no Create View.

When a user inserts a new item it posts to the Create action with httpverb post and creates the item and returns back to the List action with RedirectToAction method.

But I can not show any message(error, information etc) to the user in this style because I can not pass data between Create action and List action. How can I do that?


Solution

  • Most MVC frameworks have the ability to temporarily store a small bit of data just through the next request, for just this purpose. In ASP.NET MVC its called TempData, in Rails it's called :flash, etc.