2013-07-13 47 views
0

我喜欢做一个简单的日间交易控制。 这需要告诉我我们今天有多少交易(关闭或打开反式交易),当经理单击交易次数时,我希望将所有交易列表发送到一个不错的表格中。 但我找不到办法。甚至没有通过网络。我怎样才能返回一个列表从视图到控制器在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 =)

回答

1

你可以简单地发送SIMsales条件类似sellerId您的视图模型和剃须刀隐藏字段,以保持数据和pthe后功能(控制器上)只retrive所有这些SIMsales,你在获取FUNC计数。

(我知道那是两年前,但可能会有所帮助)

+0

10x ..那种我做的=)) – oCcSking

1

我将一个id与交易相关联的计数并传递回到控制器通过一个AJAX调用

$.ajax({ 
url: "@(Url.Action("Action", "Controller"))", 
type: "POST", 
cache: false, 
async: true, 
data: { id: 'associatedID' }, 
success: function (result) { 
    $(".Content").html(result); 
} 

});

使用传入ID

public PartialViewResult BuildTable(int id){ 
    Model model = (get results from database for id) 
    return PartialView("_Partial", model); 
} 

然后把一个div您的看法与一类内容的创建局部视图,用于显示表,并在控制器填入并返回局部视图(或任何你想要的称它)。希望这有助于。

相关问题