我喜欢做一个简单的日间交易控制。 这需要告诉我我们今天有多少交易(关闭或打开反式交易),当经理单击交易次数时,我希望将所有交易列表发送到一个不错的表格中。 但我找不到办法。甚至没有通过网络。我怎样才能返回一个列表从视图到控制器在MVC4
这里是我的尝试,但没有。 我打开建议=)
这里是我的视图模型
public class SIMcontrolsViewModel
{
public DTControls DTransactionControl { get; set; }
}
public class DTControls
{
public DateTime TDate { get; set; }
public int NumOfTransaction { get; set; }
public List<SIMsale> SIMsaleList { get; set; }
public DTControls()
{
SIMsaleList = new List<SIMsale>();
}
}
的控制器样子我填写的所有数据,我把它交给查看
[AdminAuthorization]
public ActionResult DateTransactionsControl(DateTime? date)
{
SIMcontrolsViewModel vm = new SIMcontrolsViewModel();
vm.DTransactionControl = new DTControls();
if (!date.HasValue)
date = DateTime.Now;//.Today;
vm.DTransactionControl.TDate = date.Value;
try
{
using (CompanyContext db = new CompanyContext())
{
var saleLst = db.SIMsales.ToList();
foreach (var sale in saleLst)
{
if (..)
vm.DTransactionControl.SIMsaleList.Add(sale);
}
var tCount = vm.DTransactionControl.SIMsaleList.Count;
vm.DTransactionControl.NumOfTransaction = tCount;
}
}
catch (Exception ex)
{..}
return View(vm);
}
现在在我的查看我尝试从@Html.ActionLink
发送此列表,如我们在此处所看到的。
@model oCc.IPToGo.ViewModel.SIMcontrolsViewModel
<fieldset>
<table border="0" class="display">
<thead>
<tr>
<th style="width:100px">Date</th>
<th style="width:100px">@Html.DisplayNameFor(model => model.DTransactionControl.NumOfTransaction)</th>
</tr>
</thead>
<tbody>
<tr style="text-align: center">
<td>@Model.DTransactionControl.TDate.ToShortDateString()</td>
@if (Model.DTransactionControl.NumOfTransaction != 0)
{
<td>
@Html.ActionLink(Model.DTransactionControl.NumOfTransaction.ToString(), "../SIMsale/",
new { sell = Model.DTransactionControl.SIMsaleList },
new { style = "font-weight: bold; color: Highlight" })
</td>
}
else
{
<td style="color:red">0</td>
}
</tr>
</tbody>
</table>
</fieldset>
的问题是视图/控制器谁应该得到这份名单越来越空列表。
10Q =)
10x ..那种我做的=)) – oCcSking