0

I ve got 2 seperate controller sheets not just action methods..

MY First Controller:

namespace TestLokal.Controllers
{
    public class BOUNCEController : Controller
    {
        BOUNCEDataDataContext db = new BOUNCEDataDataContext();

        //
        // GET: /BOUNCE/
        [Authorize]
        public ActionResult Index()
        {
            ViewData["Bouncers"] = new SelectList( db.Bouncers.Distinct(), "bouncer_id", "bouncer_name");
            return View();
        }
    }
}

MY Second Controller:

namespace TestLokal.Controllers
{
    public class DopplerController : Controller
    {
        //
        // GET: /Doppler/
        [Authorize]
        public ActionResult Index()
        {
            elementmodel dop = new elementmodel();
            ViewData["Dopplers"] = new SelectList( dop.BouncerList.Distinct(), "bouncer_id", "bouncer_name");
            return View();
        }
    }
}

i wanna transfer data from first to second by using this model:

MY Model:

public class elementmodel
{
    public IEnumerable<Bouncers> BouncerList { get; set; }
}

How can i achieve this?

3 Answers 3

2

You can use TempData for this.

See http://msdn.microsoft.com/en-us/library/dd394711(v=vs.90).aspx (passing data between action methods)

Sign up to request clarification or add additional context in comments.

2 Comments

are u sure that TempData can send data between seperate Controller Sheets? It looks like it only sends data between action methods. Not the whole controllers.
It doesn't matter whether the action methods are on the same controller or on different controllers. TempData is just using session state under the hood, but has a limited lifetime.
2

First of all ... are you sure you need two separate controller that has same data? In my humble opinion each controller should be responsible for handling his own group of models. If you need to have the same data in both of controllers maybe you should create some base class?

public class MyBaseController : Controller 
{   
    //shared fields & methods for example datacontext
}

public class DopplerController : MyBaseController
{
}

public class BounceController : MyBaseController
{
}

but if I'm wrong and one of your controller just need results of work from another controller you can use Coockies, Session.

2 Comments

for doing this i should have 1 controller sheet. But i got 2 seperate controller sheet in my project.
nope you would have 3 controllers. Base controller (which you can mark as abstract) and two derived controllers. But if you cannot change anything in app structure as I said you could store some data (less then 5mb which is huge...) in Session ... it's ugly but possible :)
0

2 things come immediately to mind.

  1. You can store the list of bouncers in the View as a JSON object that gets POSTed off to the other controller.
  2. You can use TempData to store it between requests. eg: http://msdn.microsoft.com/en-us/library/dd394711.aspx

1 Comment

so far json looks easier but would damage quality of project with unnecessary views and actions. I need a direct way to my second controller sheet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.