Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a view of another controller in mvc4

I have 2 controllers, SearchController and DetailsController.

the SearchController contains 2 views which contain form.

I want to redirect to a view of the details controller on the [HttpPost] action of my view in the SearchController

Is this possible???

like image 619
23nigam Avatar asked Jan 01 '13 13:01

23nigam


1 Answers

You could try RedirectToAction if you are doing some processing in the first controller and then sending the result to another controller.

View

using(@Html.BeginForm("firstaction", "search", FormMethod.Post)){

   // form stuff
}

Controller

public class SearchController
{

      [HttpPost]
      public ActionResult FirstAction()
      {
          // do initial processing in the first controller
          // e.g persisting changed on Edit Screen

          return RedirectToAction("SecondAction","Details");

      }
}

public class DetailsController
{
     public ActionResult SecondAction()
      {
          // do remaining processing in the first controller
          // fetching data for a grid and displaying the grid of items

          return View();
      }
}
like image 64
frictionlesspulley Avatar answered Nov 07 '22 05:11

frictionlesspulley