システムにいくつかの変更を加えていますが、私は誰かが助けてくれることを望んでいたことを例外として実行しましたか?私が得ているエラーは次のとおりです。MVCエラー: 'System.Collections.Generic.IEnumerable`1タイプのモデルアイテムが必要です
Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Collections.Generic.List
1[System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[MyApp.Data.aspnet_Users]'.
基本的には、非アクティブなユーザーのリストを表示したいと考えています。ここに私が書いたコントローラがあります:
public ActionResult InactiveUsers()
{
using (ModelContainer ctn = new ModelContainer())
{
aspnet_Users users = new aspnet_Users();
DateTime duration = DateTime.Now.AddDays(-3);
var inactive = from usrs in ctn.aspnet_Users
where usrs.LastActivityDate <= duration
orderby usrs.LastActivityDate ascending
select usrs.UserName;
return View(inactive.ToList());
}
}
ここから私は部分的なビューを追加しました。誰かが興味を持っているなら、それのためのコードはここにあります。通常の表示 - >リストの追加だけです。ここ
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<MyApp.Data.aspnet_Users>>" %>
<table>
<tr>
<th></th>
<th>
ApplicationId
</th>
<th>
UserId
</th>
<th>
UserName
</th>
<th>
LoweredUserName
</th>
<th>
MobileAlias
</th>
<th>
IsAnonymous
</th>
<th>
LastActivityDate
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id=item.UserId }) %> |
<%: Html.ActionLink("Details", "Details", new { id=item.UserId })%> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.UserId })%>
</td>
<td>
<%: item.ApplicationId %>
</td>
<td>
<%: item.UserId %>
</td>
<td>
<%: item.UserName %>
</td>
<td>
<%: item.LoweredUserName %>
</td>
<td>
<%: item.MobileAlias %>
</td>
<td>
<%: item.IsAnonymous %>
</td>
<td>
<%: String.Format("{0:g}", item.LastActivityDate) %>
</td>
</tr>
<% } %>
</table>
<p>
<%: Html.ActionLink("Create New", "Create") %>
</p>
万全を期すためには、私は部分的にレンダリングインデックスページである:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Administrator.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<% Html.RenderAction("InactiveUsers"); %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Header" runat="server">
</asp:Content>
誰もが何かアドバイスを持っている場合は、私は非常に感謝されると思います:)
治療を受けました。ありがとう@サンジャ。 – 109221793
@TaraWalsh問題なし、ちょうだい –