2014-12-08 50 views
0

我正在研究一個具有layout.cshtml的項目,該項目定義了佈局的幾個部分。我現在想要的是在layout.cshtml上的div中指定我應該使用哪個AngularJS控制器。AngularJS和Asp.net mvc5

因此index.cshtml應該指定--indexcontroller。 account.cshml應指定 - accountcontroller。

我可以根據特定頁面中的代碼使用某種類型的renderAttribute嗎?我可以將div移動到特定部分,但仍將我的內容保留在主佈局頁面中?

回答

1

我以前用過ViewBag來實現這個功能。

在您的帳戶控制:

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

然後在你的佈局,你可以簡單地使用在ViewBag特性集:

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