У меня есть 2 разных имени клиента в ViewBag.Customernames.
Я пытаюсь вызвать список имен клиентов внутри загрузочного загрузчика.
GraphService.cs:
public static List<string> GetCustomerNames(List<ResultsItem> groups)
{
List<string> names = new List<string>();
foreach (var group in groups)
{
if (group.DisplayName.StartsWith("Customer:", StringComparison.InvariantCultureIgnoreCase))
{
var split = group.DisplayName.Split(':');
if (split.Length > 1)
names.Add(split[1]);
}
}
return names;
}
HomeController.cs
if (User.Identity.IsAuthenticated)
{
try
{
// Get users's email.
//email = email ?? User.FindFirst("preferred_username")?.Value;
email = email ?? User.FindFirst(ClaimTypes.Email)?.Value;
ViewData["Email"] = email;
// Get user's id for token cache.
var identifier = User.FindFirst(Startup.ObjectIdentifierType)?.Value;
// Initialize the GraphServiceClient.
var graphClient = _graphSdkHelper.GetAuthenticatedClient(identifier);
var groups = await GraphService.GetMyMemberOfGroups(graphClient);
ViewBag.CustomerNames = GraphService.GetCustomerNames(groups);
if (ViewBag.CustomerNames.Count > 0)
{
ViewBag.CustomerName = ViewBag.CustomerNames[0];
}
ViewBag.givenName = GraphService.GetGivenName(groups);
ViewBag.RoleNames = GraphService.GetRoleNames(groups);
Startup.Roles = ViewBag.RoleNames;
ViewBag.UserName = User.FindFirst(ClaimTypes.GivenName)?.Value;
ViewBag.LastName = User.FindFirst(ClaimTypes.Surname)?.Value;
}
view
<li>
@foreach (var i in ViewBag.Customernames)
{
<a href="#" id="userAvatar" data-container="body" data-toggle="popover" data-trigger="focus" title="@(ViewBag.UserName) @(ViewBag.LastName)" data-content="Customer : @i <hr/><br/><button class='btn'><i class='fa fa-sign-out fa' style='color:red'> </i><a role='button' href='/Account/SignOut' style='text-decoration:none'> LOGOUT</a></button>">
<strong title="@User.Identity.Name"> @(ViewBag.UserName[0])@(ViewBag.LastName[0])</strong>
</a>
}
</li>
Работает нормально, но создает еще один#userAvatar (я знаю, что это не правильный путь).
Вывод

Вопрос: Какиспользовать foreach
только для data-content
?