0

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?

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

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.