亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

傳入字典的模型項的類型為“something” 傳入字典的模型項的類型為

傳入字典的模型項的類型為“something” 傳入字典的模型項的類型為

C#
精慕HU 2022-07-10 10:34:39
我意識到這里有太多類似的問題。但我無法用任何這些解決方案解決我的問題。 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; }  }}如果你需要,這是我的模型。所以,我試圖獲得搜索結果,但是當我點擊提交按鈕時,它給了我“傳入字典的模型項的類型為‘System.Data.Entity.Infrastructure.DbQuery`1[datingo.Models.EntityFramework.userAcc]’,但該字典需要‘datingo.Models.EntityFramework’類型的模型項。用戶帳戶'?!卞e誤。順便說一句,我知道我沒有為表格列表添加所需的視圖,但至少現在對我來說沒有必要。我不知道該怎么做,有很多關于這個列表和搜索操作的教程,它們工作正常但我的不是。
查看完整描述

2 回答

?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

嘗試更改return View(users);return View(users.ToList());



查看完整回答
反對 回復 2022-07-10
?
GCT1015

TA貢獻1827條經驗 獲得超4個贊

我解決了我的問題。

在我看來,我用

@model IEnumerable<datingo.Models.EntityFramework.userAcc>

正如你所記得的。

而且在我提到的布局中,我使用了另一個@model,比如

@model datingo.Models.EntityFramework.userAcc

當我刪除布局模型部分時,它是固定的。


查看完整回答
反對 回復 2022-07-10
  • 2 回答
  • 0 關注
  • 105 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號