This project is read-only.

Pass data between controllers

Aug 5, 2010 at 9:41 PM
Hello, I have some problem with pass data between controllers (forms), from controller x i navigate to y controller which execute view with edit form, after editing form by user i goBack. How to retrive data from Model in y controller after go back. Best regards
Aug 5, 2010 at 11:24 PM
Edited Aug 5, 2010 at 11:27 PM
Hello, You can use the container to centralize all your model classes, and then use that to access.
For each controller, set a property for the container to gain access all the models.

On the example of the source code:
LoginController.cs

public class LoginController : Controller
{
public Container Container
{
get;
set;
}
}


ApplicationManager.cs

container.Register<LoginForm>(c => new LoginForm());
container.Register<LoginController>(c => new LoginController(c.Resolve<LoginForm>()))
.InitializedBy((c, v) => v.Container = c);

Example:
container.Register<ModelClass>(c => new ModelClass());


On any controller:

Container.Resolve<ModelClass>();