0

I have a target to create a nested architecture of view/controller. For example: we have few areas in webpage. All this areas managed by its own controller. In another words I need to create independend pages and then join them in one page. Please see the image: enter image description here

So is it possible and where I can read about it? Thanks.

2 Answers 2

2

Yes you can achieve this by simply calling

@Html.Action("ActionName", "ControllerName");

Example:

in your case you can do like this

Controller1

 public ActionResult View1()
    {

        return View("View1");
    }

Controller2

 public ActionResult View2()
    {

        return View("View2");
    }

Controller3

 public ActionResult View3()
    {

        return View("View3");
    }

Calling in main page:

@Html.Action("View1", "Controller1");
@Html.Action("View2", "Controller2");
@Html.Action("View2", "Controller2");

call these in different section of main page wherever you want.

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

Comments

1

You can use @Html.Action() to render child views from different controllers

public class FirstController : Controller
{
  public ActionResult Index()
  {
    return View();
  }
}

public class SecondController : Controller
{
  [ChildActionOnly]
  public ActionResult Method1()
  {
    return PartialView();
  }
}

public class ThirdController : Controller
{
  [ChildActionOnly]
  public ActionResult Method2(int ID)
  {
    return PartialView();
  }
}

Index View (FirstController)

....
@Html.Action("Method1", "Second")
@Html.Action("Method2", "Third", new { ID = someValue })

You can also use @{ Html.RenderAction(); which is more efficient is you are generating a lot of html.

Comments

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.