的我有是強類型的視圖asp.net MVC視圖和我有一個控制器,它返回 根據提供的ID與IList用戶。我收到以下錯誤信息:asp.net MVC模型項的類型是List
傳遞到字典中的模型項類型爲'System.Collections.Generic.List`1 [Data.User]',但該字典需要一個類型爲' Data.User」。
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Data.User>" %>
<% using (Html.BeginForm())
{%> <%= Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%= Html.LabelFor(model => model.Id) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Id) %>
<%= Html.ValidationMessageFor(model => model.Id) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.UserName) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.UserName) %>
<%= Html.ValidationMessageFor(model => model.UserName) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.Email) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Email) %>
<%= Html.ValidationMessageFor(model => model.Email) %>
public ActionResult EditUser(int id)
{
var usr = _UsrService.GerUserById(id).ToList<User>();
return View(usr);
}
我編輯了你的帖子,從控制器與視圖分離。如果刪除了兩個代碼塊之間的文本(我只是寫了「控制器」),它看起來像一個單一的代碼塊(這看起來很奇怪) – 2010-07-06 18:42:48
還,這是一個錯字? 'GerUserById'應該不會是'GetUserById' – 2010-07-06 18:46:04