AngularJS和Asp.net mvc5

问题描述:

我正在研究一个具有layout.cshtml的项目,该项目定义了布局的几个部分。我现在想要的是在layout.cshtml上的div中指定我应该使用哪个AngularJS控制器。AngularJS和Asp.net mvc5

因此index.cshtml应该指定--indexcontroller。 account.cshml应指定 - accountcontroller。

我可以根据特定页面中的代码使用某种类型的renderAttribute吗?我可以将div移动到特定部分,但仍将我的内容保留在主布局页面中?

我以前用过ViewBag来实现这个功能。

在您的帐户控制:

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

然后在你的布局,你可以简单地使用在ViewBag特性集:

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