Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I return a list from view to controller in MVC4
    primarykey
    data
    text
    <p>I like to do one simple control for day transactions. That need to show me how much transaction we have this day (close or open trans) and when the manager click the number of transaction I would like to send all this list of transactions into a nice table. But I can't find the way to do it. Not even across the web.</p> <p>here is my try but nothing. I am open for suggestion =)</p> <p>Here is my <strong>ViewModel</strong> </p> <pre><code>public class SIMcontrolsViewModel { public DTControls DTransactionControl { get; set; } } public class DTControls { public DateTime TDate { get; set; } public int NumOfTransaction { get; set; } public List&lt;SIMsale&gt; SIMsaleList { get; set; } public DTControls() { SIMsaleList = new List&lt;SIMsale&gt;(); } } </code></pre> <p>the <strong>Controller</strong> look like I fill all the data and I sent it to view </p> <pre><code> [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); } </code></pre> <p>Now on my <strong>View</strong> I try to send this list from this <code>@Html.ActionLink</code> like we can see here.</p> <pre><code>@model oCc.IPToGo.ViewModel.SIMcontrolsViewModel &lt;fieldset&gt; &lt;table border="0" class="display"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th style="width:100px"&gt;Date&lt;/th&gt; &lt;th style="width:100px"&gt;@Html.DisplayNameFor(model =&gt; model.DTransactionControl.NumOfTransaction)&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr style="text-align: center"&gt; &lt;td&gt;@Model.DTransactionControl.TDate.ToShortDateString()&lt;/td&gt; @if (Model.DTransactionControl.NumOfTransaction != 0) { &lt;td&gt; @Html.ActionLink(Model.DTransactionControl.NumOfTransaction.ToString(), "../SIMsale/", new { sell = Model.DTransactionControl.SIMsaleList }, new { style = "font-weight: bold; color: Highlight" }) &lt;/td&gt; } else { &lt;td style="color:red"&gt;0&lt;/td&gt; } &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/fieldset&gt; </code></pre> <p>The <strong>problem</strong> is that the view/controller who supposed to get this list is getting an empty list.</p> <p>10Q =)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload