Asp.net mvc 通过IEnumerable<;SomeModel>;还有一些要查看的模型
我正在使用:Asp.net mvc 通过IEnumerable<;SomeModel>;还有一些要查看的模型,asp.net-mvc,list,ienumerable,Asp.net Mvc,List,Ienumerable,我正在使用: @model IEnumerable<SomeModel1> 有没有一种方法可以在不将模型放入父模型的情况下实现这一点 更新: 查看页面: <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <table class="table table-bordered tabl
@model IEnumerable<SomeModel1>
有没有一种方法可以在不将模型放入父模型的情况下实现这一点
更新:
查看页面:
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr>
<th class="text-center">
Active
</th>
<th class="text-center">
Email Address
</th>
<th class="text-center">
First name
</th>
<th class="text-center">
Last Name
</th>
<th class="text-center">
Company
</th>
<th class="text-center">
permissions
</th>
<th class="text-center">
Machine<p>Limit</p>
</th>
<th class="text-center">
Machines<p>Consumed</p>
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td style="display:none" >@Html.DisplayFor(model => item.UserId)</td>
<td align="center">
<div class="btn-group btn-toggle">
@if (item.ActiveUser)
{
<button class="btn btn-sm btn-success active">ON</button>
<button class="btn btn-sm btn" onclick="DeActivateUser('@item.UserId')">OFF</button>
}
else
{
<button class="btn btn-sm btn" onclick="ActivateUser('@item.UserId')">ON</button>
<button class="btn btn-sm btn-success active">OFF</button>
}
</div>
</td>
<td>@Html.DisplayFor(model => item.EmailAddress)</td>
<td>@Html.DisplayFor(model => item.FirstName)</td>
<td>@Html.DisplayFor(model => item.LastName)</td>
<td>@Html.DisplayFor(model => item.Company)</td>
<td>
@Html.DisplayFor(model => item.UserPermission)
<a href="#" class="dropdown-toggle glyphicon glyphicon-chevron-down" data-toggle="dropdown"><b class="dropdown-menu"></b> </a>
<ul class="dropdown-menu">
<li><a onclick="ChangePermission('@item.UserId', '3')">View Only</a></li>
<li><a onclick="ChangePermission('@item.UserId', '4')">View - Print</a></li>
<li><a onclick="ChangePermission('@item.UserId', '5')">View - One Print</a></li>
<li><a onclick="ChangePermission('@item.UserId', '6')">Expire by Use - 5 Opens</a></li>
<li><a onclick="ChangePermission('@item.UserId', '7')">Expire After 5 Days</a></li>
</ul>
</td>
<td align="center">@Html.DisplayFor(model => item.MachineLimit)</td>
<td align="center">@Html.DisplayFor(model => item.MachineCount)</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
<section id="addUser">
@using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h2>Add Authorized User(s): </h2>
<hr style="height:7pt;" />
<!-- <hr style="height:0pt; visibility:hidden;" /> -->
<button class="btn btn-default btn-success btn-lg" data-target="#modalId" data-toggle="modal" type="button">
<span class="glyphicon glyphicon-plus"></span> ADD NEW USER
</button>
<div class="modal fade" id="modalId" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add Authorized User(s)</h4>
</div>
<div class="modal-body">
@Html.ValidationSummary()
<!-- <div class="col-md-4"> -->
<div class="form-group">
@Html.LabelFor(m => m. ().FirstName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FirstOrDefault().FirstName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FirstOrDefault().LastName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FirstOrDefault().LastName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FirstOrDefault().EmailAddress, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FirstOrDefault().EmailAddress, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FirstOrDefault().Company, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FirstOrDefault().Company, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FirstOrDefault().UserPermission, new { @class = "col-md-2 control-label" })
<div class="col-md-3 control-label">
@Html.DropDownListFor(m => m.FirstOrDefault().UserPermission, new SelectList(new List<Object>
{
new { value = "2" , text = "View Only"},
new { value = "3" , text = "View - Print" },
new { value = "4" , text = "View - One Print" },
new { value = "5" , text = "Expire by 5 Use" },
new { value = "6" , text = "Expire by 5 Date" }
},
"value", "text", "ViewOnly"))
</div>
@Html.LabelFor(m => m.FirstOrDefault().MachineLimit, new { @class = "col-md-2 control-label" })
<div class="col-md-2 control-label">
@Html.DropDownListFor(m => m.FirstOrDefault().MachineLimit, new SelectList(new List<Object>
{
new { value = "1" , text = "1"},
new { value = "2" , text = "2" },
new { value = "3" , text = "3" },
new { value = "4" , text = "4" },
new { value = "5" , text = "5" }
},
"value", "text", 1))
</div>
</div>
</div>
<div class="modal-footer">
<div class="col-md-3 col-md-10 control-label">
<input type="submit" class="btn btn-default" value="Select/Add" name="Action:Insert" />
</div>
</div>
</div>
</div>
</div>
}
</section>
活跃的
电子邮件地址
名字
姓
单位
权限
机器极限
机器消耗量
@foreach(模型中的var项目)
{
@DisplayFor(model=>item.UserId)
@if(item.ActiveUser)
{
在…上
关
}
其他的
{
在…上
关
}
@DisplayFor(model=>item.EmailAddress)
@DisplayFor(model=>item.FirstName)
@DisplayFor(model=>item.LastName)
@DisplayFor(model=>item.Company)
@DisplayFor(model=>item.UserPermission)
- 仅查看
- 查看-打印
- 查看-一次打印
- 使用过期-打开5个
- 5天后到期
@DisplayFor(模型=>item.MachineLimit)
@DisplayFor(模型=>item.MachineCount)
}
@使用(Html.BeginForm(“Manage”、“Account”、FormMethod.Post、new{@class=“form horizontal”、role=“form”}))
{
@Html.AntiForgeryToken()
添加授权用户:
添加新用户
添加授权用户
@Html.ValidationSummary()
@LabelFor(m=>m.().FirstName,新的{@class=“col-md-2控制标签”})
@Html.TextBoxFor(m=>m.FirstOrDefault().FirstName,新的{@class=“form control”})
@LabelFor(m=>m.FirstOrDefault().LastName,新的{@class=“col-md-2控件标签”})
@Html.TextBoxFor(m=>m.FirstOrDefault().LastName,新的{@class=“form control”})
@LabelFor(m=>m.FirstOrDefault().EmailAddress,新的{@class=“col-md-2控制标签”})
@Html.TextBoxFor(m=>m.FirstOrDefault().EmailAddress,新的{@class=“form control”})
@LabelFor(m=>m.FirstOrDefault().Company,新的{@class=“col-md-2控制标签”})
@Html.TextBoxFor(m=>m.FirstOrDefault().Company,new{@class=“form control”})
@LabelFor(m=>m.FirstOrDefault().UserPermission,新的{@class=“col-md-2控制标签”})
@Html.DropDownListFor(m=>m.FirstOrDefault().UserPermission,new SelectList(new List
{
新建{value=“2”,text=“仅查看”},
新建{value=“3”,text=“查看-打印”},
新建{value=“4”,text=“查看-一次打印”},
新的{value=“5”,text=“过期5次使用”},
新建{value=“6”,text=“在5日前到期”}
},
“值”、“文本”、“仅查看”))
@LabelFor(m=>m.FirstOrDefault().MachineLimit,新的{@class=“col-md-2控件标签”})
@Html.DropDownListFor(m=>m.FirstOrDefault().MachineLimit,新选择列表(新列表
{
新的{value=“1”,text=“1”},
新的{value=“2”,text=“2”},
新的{value=“3”,text=“3”},
新的{value=“4”,text=“4”},
新{值
@model WebApplication8.Models.ManageUserViewModel
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr>
<th class="text-center">
Active
</th>
<th class="text-center">
Email Address
</th>
<th class="text-center">
First name
</th>
<th class="text-center">
Last Name
</th>
<th class="text-center">
Company
</th>
<th class="text-center">
permissions
</th>
<th class="text-center">
Machine<p>Limit</p>
</th>
<th class="text-center">
Machines<p>Consumed</p>
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td style="display:none" >@Html.DisplayFor(model => item.UserId)</td>
<td align="center">
<div class="btn-group btn-toggle">
@if (item.ActiveUser)
{
<button class="btn btn-sm btn-success active">ON</button>
<button class="btn btn-sm btn" onclick="DeActivateUser('@item.UserId')">OFF</button>
}
else
{
<button class="btn btn-sm btn" onclick="ActivateUser('@item.UserId')">ON</button>
<button class="btn btn-sm btn-success active">OFF</button>
}
</div>
</td>
<td>@Html.DisplayFor(model => item.EmailAddress)</td>
<td>@Html.DisplayFor(model => item.FirstName)</td>
<td>@Html.DisplayFor(model => item.LastName)</td>
<td>@Html.DisplayFor(model => item.Company)</td>
<td>
@Html.DisplayFor(model => item.UserPermission)
<a href="#" class="dropdown-toggle glyphicon glyphicon-chevron-down" data-toggle="dropdown"><b class="dropdown-menu"></b> </a>
<ul class="dropdown-menu">
<li><a onclick="ChangePermission('@item.UserId', '3')">View Only</a></li>
<li><a onclick="ChangePermission('@item.UserId', '4')">View - Print</a></li>
<li><a onclick="ChangePermission('@item.UserId', '5')">View - One Print</a></li>
<li><a onclick="ChangePermission('@item.UserId', '6')">Expire by Use - 5 Opens</a></li>
<li><a onclick="ChangePermission('@item.UserId', '7')">Expire After 5 Days</a></li>
</ul>
</td>
<td align="center">@Html.DisplayFor(model => item.MachineLimit)</td>
<td align="center">@Html.DisplayFor(model => item.MachineCount)</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
<section id="addUser">
@using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h2>Add Authorized User(s): </h2>
<hr style="height:7pt;" />
<!-- <hr style="height:0pt; visibility:hidden;" /> -->
<button class="btn btn-default btn-success btn-lg" data-target="#modalId" data-toggle="modal" type="button">
<span class="glyphicon glyphicon-plus"></span> ADD NEW USER
</button>
<div class="modal fade" id="modalId" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add Authorized User(s)</h4>
</div>
<div class="modal-body">
@Html.ValidationSummary()
<!-- <div class="col-md-4"> -->
<div class="form-group">
@Html.LabelFor(m => m. ().FirstName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FirstOrDefault().FirstName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FirstOrDefault().LastName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FirstOrDefault().LastName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FirstOrDefault().EmailAddress, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FirstOrDefault().EmailAddress, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FirstOrDefault().Company, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FirstOrDefault().Company, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FirstOrDefault().UserPermission, new { @class = "col-md-2 control-label" })
<div class="col-md-3 control-label">
@Html.DropDownListFor(m => m.FirstOrDefault().UserPermission, new SelectList(new List<Object>
{
new { value = "2" , text = "View Only"},
new { value = "3" , text = "View - Print" },
new { value = "4" , text = "View - One Print" },
new { value = "5" , text = "Expire by 5 Use" },
new { value = "6" , text = "Expire by 5 Date" }
},
"value", "text", "ViewOnly"))
</div>
@Html.LabelFor(m => m.FirstOrDefault().MachineLimit, new { @class = "col-md-2 control-label" })
<div class="col-md-2 control-label">
@Html.DropDownListFor(m => m.FirstOrDefault().MachineLimit, new SelectList(new List<Object>
{
new { value = "1" , text = "1"},
new { value = "2" , text = "2" },
new { value = "3" , text = "3" },
new { value = "4" , text = "4" },
new { value = "5" , text = "5" }
},
"value", "text", 1))
</div>
</div>
</div>
<div class="modal-footer">
<div class="col-md-3 col-md-10 control-label">
<input type="submit" class="btn btn-default" value="Select/Add" name="Action:Insert" />
</div>
</div>
</div>
</div>
</div>
}
</section>
SomeModel myModel;
return View(new List<SomeModel> { myModel };
// controller
ViewBag.SomeModel = someModel;
// view
@ViewBag.SomeModel.SomeProperty