In my MVC app the controller gets the data (model) from an external API (so there is no model class being used) and passes that to the view. The data (model) has a container
You should not call a controller from the view.
Add a property to your view model, set it in the controller, and use it in the view.
Here is an example:
MyViewModel.cs:
public class MyViewModel
{ ...
public bool ShowAdmin { get; set; }
}
MyController.cs:
public ViewResult GetAdminMenu()
{
MyViewModelmodel = new MyViewModel();
model.ShowAdmin = userHasPermission("Admin");
return View(model);
}
MyView.cshtml:
@model MyProj.ViewModels.MyViewModel
@if (@Model.ShowAdmin)
{
}
..\Views\Shared\ _Layout.cshtml:
@using MyProj.ViewModels.Common;
....
@Html.Action("GetAdminMenu", "Layout")