.net 如何访问popover中的循环变量?
我在ViewBag.Customernames中有两个不同的客户名称 我试图调用bootstrap popover中的客户名称列表 GraphService.cs:.net 如何访问popover中的循环变量?,.net,razor,.net,Razor,我在ViewBag.Customernames中有两个不同的客户名称 我试图调用bootstrap popover中的客户名称列表 GraphService.cs: public static List<string> GetCustomerNames(List<ResultsItem> groups) { List<string> names = new List<string>();
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;
}
查看
<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>
@foreach(ViewBag.Customernames中的变量i)
{
">
@(ViewBag.UserName[0])@(ViewBag.LastName[0])
}
这很好,但又创造了一个用户化身(我知道这不是一个正确的方法)
输出
问题:如何仅对
数据内容使用foreach
?我得出以下结论:
<li>
<a href="#" id="userAvatar" data-container="body" data-toggle="popover"
title="<strong>@(ViewBag.UserName) @(ViewBag.LastName)</strong><br/>@User.Identity.Name"
data-content="<button class='btn btl-lg btn-block'><i class='fa fa-sign-out fa' style='color:red'> </i><a role='button' href='/Account/SignOut' style='text-decoration:none'> LOGOUT</a></button><hr/><select id='listOfCust' class='btn btn-info btl-lg btn-block'>CUSTOMER : @foreach (var i in ViewBag.CustomerNames){<option id='@i' value='@i' class='btn divider'>@i</option>}</selct><br/>">
<strong title="@User.Identity.Name"> @(ViewBag.UserName[0])@(ViewBag.LastName[0])</strong>
</a>
</li>
当集合有多个项时,循环中相同的Id
值将生成无效的HTML。Id值应是唯一的。
<li>
<a href="#" id="userAvatar" data-container="body" data-toggle="popover"
title="<strong>@(ViewBag.UserName) @(ViewBag.LastName)</strong><br/>@User.Identity.Name"
data-content="<button class='btn btl-lg btn-block'><i class='fa fa-sign-out fa' style='color:red'> </i><a role='button' href='/Account/SignOut' style='text-decoration:none'> LOGOUT</a></button><hr/><select id='listOfCust' class='btn btn-info btl-lg btn-block'>CUSTOMER : @foreach (var i in ViewBag.CustomerNames){<option id='@i' value='@i' class='btn divider'>@i</option>}</selct><br/>">
<strong title="@User.Identity.Name"> @(ViewBag.UserName[0])@(ViewBag.LastName[0])</strong>
</a>
</li>
<select id='listOfCust' class='btn btn-info btl-lg btn-block'>CUSTOMER : @foreach (var i in ViewBag.CustomerNames){<option id='@i' value='@i' class='btn divider'>@i</option>}</selct>