你好,我有一個叫做用戶的數據模型。在控制器我與LINQ方法的所有用戶,我想在視圖中顯示。這是很簡單的,但我有一個問題,我解決不了.l'erreur是System.InvalidOperationException:傳遞到字典的模型項的類型是「System.Data.Linq.Table 1[WebApplication1.Utilisateur] », mais ce dictionnaire requiert un élément de modèle de type « System.Collections.Generic.IEnumerable
1 [WebApplication1.Models.Utilisateur]「。 我試圖與IEnumerable的lstUtil = ctx.Utilisateur;它改變了什麼。我試圖ctx.Utilisateur.Toliste();它也不改變......MVC LINQ視圖控制器錯誤
這裏是我的代碼:
public class Utilisateur
{
[Required]
[DisplayName("Login")]
public string Name { get; set; }
[Required]
[DisplayName("Mot de passe")]
[DataType(DataType.Password)]
public string Pass { get; set; }
}
public class TestController : Controller
{
public ActionResult Index()
{
using (var ctx = new BddDataClassesDataContext())
{
var lstUtil = ctx.Utilisateur;
return View(lstUtil);
}
}
}
index.cshtml:
@model IEnumerable<WebApplication1.Models.Utilisateur>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Pass)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Pass)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
請用英文我有一個 –
數據模型歸仁s'intitule用戶。我嘗試檢查,收集所有的DATAS在數據庫中的表和展示給我看在我看來,針對我有一個關於該種支票和期望是什麼鑑於發送的數據錯誤。 – Mania
堆棧溢出需要很高興能在英語:https://meta.stackoverflow.com/questions/297673/how-do-i-deal-with-non-english-content –