Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.Net MVC - Models and User Controls
    text
    copied!<p>I have a View with a Master Page. The user control makes use of a Model:</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;BudgieMoneySite.Models.SiteUserLoginModel&gt;" %&gt; </code></pre> <p>This user control is shown on all screens (Part of the Master Page). If the user is logged in, it shows a certain text, and if the user isn't logged in, it offers a login box.</p> <p>That is working OK.</p> <p>Now, I am adding my first functional screen. So I created a new view... and, well, i generated the basic view code for me when I selected the controller method, and said 'Create View'.</p> <p>My Controller has this code:</p> <pre><code> public ActionResult Transactions() { List&lt;AccountTransactionDetails&gt; trans = GetTransactions(); return View(trans); } private List&lt;AccountTransactionDetails&gt; GetTransactions() { List&lt;AccountTransactionDto&gt; trans = Services.TransactionServices.GetTransactions(); List&lt;AccountTransactionDetails&gt; reply = new List&lt;AccountTransactionDetails&gt;(); foreach(var t in trans) { AccountTransactionDetails a = new AccountTransactionDetails(); foreach (var line in a.Transactions) { AccountTransactionLine l = new AccountTransactionLine(); l.Amount = line.Amount; l.SubCategory = line.SubCategory; l.SubCategoryId = line.SubCategoryId; a.Transactions.Add(l); } reply.Add(a); } return reply; } </code></pre> <p>So, my view was generated with this:</p> <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;System.Collections.Generic.List&lt;BudgieMoneySite.Models.AccountTransactionDetails&gt;&gt;" %&gt; </code></pre> <p> Found &lt;%=Model.Count() %> Transactions. </p> <p>All I want to show for now is the number of records I will be displaying.</p> <p>When I run it, I get an error:</p> <p>"The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[BudgieMoneySite.Models.AccountTransactionDetails]', but this dictionary requires a model item of type 'BudgieMoneySite.Models.SiteUserLoginModel'."</p> <p>It looks like the user control is being rendered first, and as the Model from the controller is my List&lt;>, it's breaking!</p> <p>What am I doing wrong?</p>
 

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