传入字典的模型项的类型为“某物”传入字典的模型项的类型为 "something else"
The model item passed into the dictionary is of type " something" The model item passed into the dictionary is of type "something else"
我意识到 here.But 中有太多类似的问题,我无法用这些解决方案解决我的问题。
datingDbEntities db = new datingDbEntities();
[Authorize]
[HttpGet]
public ActionResult FindMatch()
{
return View();
}
[HTTPPost]
public ActionResult FindMatch(string searchString)
{
var users = from m in db.userAcc
select m;
if (!String.IsNullOrEmpty(searchString))
{
users = users.Where(s => s.userAd.Contains(searchString));
}
return View(users);
}
这是我的行为
@model IEnumerable<datingo.Models.EntityFramework.userAcc>
<h2>Index</h2>
<p>
@Html.ActionLink("FindMatch", "Home")
@using (Html.BeginForm("FindMatch", "Home", FormMethod.Post))
{
<p>
Title: @Html.TextBox("SearchString") <br />
<input type="submit" value="Filter" />
</p>
}
这是我的看法。
namespace datingo.Models.EntityFramework
{
using System;
using System.Collections.Generic;
public partial class userAcc
{
public int userId { get; set; }
public string userName { get; set; }
public string userPw { get; set; }
public string userMail { get; set; }
public Nullable<bool> userGender { get; set; }
public string userAd { get; set; }
public string userSoyad { get; set; }
public Nullable<int> userBoy { get; set; }
public Nullable<int> userKilo { get; set; }
public string userHair { get; set; }
public string userEye { get; set; }
public string userCountry { get; set; }
public string userFavTeam { get; set; }
public string userBurc { get; set; }
public string userFavMusic { get; set; }
public string userFavFilm { get; set; }
public string userMeslek { get; set; }
public string userEgitim { get; set; }
public byte[] userPhoto { get; set; }
public Nullable<System.DateTime> userBirthday { get; set; }
public int commentParentId { get; set; }
}
}
如果你需要,这是我的模型。
所以,我试图获取搜索结果,但是当我点击提交按钮时,它给了我
"The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[datingo.Models.EntityFramework.userAcc]', but this dictionary requires a model item of type 'datingo.Models.EntityFramework.userAcc'."
error.By 顺便说一句,我知道我没有为 table 列表添加所需的视图,但这对我来说不是必需的,至少 now.I 不知道该怎么做,有许多关于此列表和搜索操作的教程,它们工作正常但我的不是。
尝试将 return View(users);
更改为 return View(users.ToList());
我解决了我的问题。
在我看来我使用了
@model IEnumerable<datingo.Models.EntityFramework.userAcc>
如你所记得。
而且在我提到的布局中,我使用了另一个@model,比如
@model datingo.Models.EntityFramework.userAcc
当我删除布局模型部分时,它已修复。
我意识到 here.But 中有太多类似的问题,我无法用这些解决方案解决我的问题。
datingDbEntities db = new datingDbEntities();
[Authorize]
[HttpGet]
public ActionResult FindMatch()
{
return View();
}
[HTTPPost]
public ActionResult FindMatch(string searchString)
{
var users = from m in db.userAcc
select m;
if (!String.IsNullOrEmpty(searchString))
{
users = users.Where(s => s.userAd.Contains(searchString));
}
return View(users);
}
这是我的行为
@model IEnumerable<datingo.Models.EntityFramework.userAcc>
<h2>Index</h2>
<p>
@Html.ActionLink("FindMatch", "Home")
@using (Html.BeginForm("FindMatch", "Home", FormMethod.Post))
{
<p>
Title: @Html.TextBox("SearchString") <br />
<input type="submit" value="Filter" />
</p>
}
这是我的看法。
namespace datingo.Models.EntityFramework
{
using System;
using System.Collections.Generic;
public partial class userAcc
{
public int userId { get; set; }
public string userName { get; set; }
public string userPw { get; set; }
public string userMail { get; set; }
public Nullable<bool> userGender { get; set; }
public string userAd { get; set; }
public string userSoyad { get; set; }
public Nullable<int> userBoy { get; set; }
public Nullable<int> userKilo { get; set; }
public string userHair { get; set; }
public string userEye { get; set; }
public string userCountry { get; set; }
public string userFavTeam { get; set; }
public string userBurc { get; set; }
public string userFavMusic { get; set; }
public string userFavFilm { get; set; }
public string userMeslek { get; set; }
public string userEgitim { get; set; }
public byte[] userPhoto { get; set; }
public Nullable<System.DateTime> userBirthday { get; set; }
public int commentParentId { get; set; }
}
}
如果你需要,这是我的模型。
所以,我试图获取搜索结果,但是当我点击提交按钮时,它给了我
"The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[datingo.Models.EntityFramework.userAcc]', but this dictionary requires a model item of type 'datingo.Models.EntityFramework.userAcc'."
error.By 顺便说一句,我知道我没有为 table 列表添加所需的视图,但这对我来说不是必需的,至少 now.I 不知道该怎么做,有许多关于此列表和搜索操作的教程,它们工作正常但我的不是。
尝试将 return View(users);
更改为 return View(users.ToList());
我解决了我的问题。
在我看来我使用了
@model IEnumerable<datingo.Models.EntityFramework.userAcc>
如你所记得。
而且在我提到的布局中,我使用了另一个@model,比如
@model datingo.Models.EntityFramework.userAcc
当我删除布局模型部分时,它已修复。