Patrick
Patrick

Reputation: 383

AngularJS and Asp.net mvc5

I'm working on a project that has a layout.cshtml, which defines several sections of the layout. What I now want is in a div that is on the to layout.cshtml specify which AngularJS controller I should use.

Thus the index.cshtml should specify - indexcontroller. The account.cshml should specify - accountcontroller.

Can I use some sort of renderAttribute based on code below in the specific page? Can I move the div to the specific section but still keep my content in my main layout page?

Upvotes: 0

Views: 115

Answers (1)

rmorrin
rmorrin

Reputation: 2485

I've used ViewBag to achieve this before.

In your Account Controller:

public class AccountController : Controller
{
    public ActionResult Index()
    {
        ViewBag.AngularController = "accountcontroller"
        return View();
    }
}

Then in your layout you can simply use the property set on the ViewBag:

<div ng-controller="@ViewBag.AngularController">
    {{AngularGoodnessHere}}
</div>

Upvotes: 1

Related Questions