Я понял, что здесь слишком много подобных вопросов. Но я не могу решить свою проблему ни с одним из этих решений.
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; }
}
}
и это моя модель, если вам нужно.
Итак, я пытаюсь получить результаты поиска, но когда я нажимаю кнопку «Отправить», это дает мне
"Элемент модели, передаваемый в словарь, имеет тип 'System.Data.Entity.Infrastructure.DbQuery`1 [Datingo.Models.EntityFramework.userAcc]', но для этого словаря требуется элемент модели типа 'Datingo.Models. .EntityFramework.userAcc. "
ошибка. Кстати, я знаю, что не добавил нужного представления для перечисления таблиц, но это мне не нужно, по крайней мере, сейчас. работают нормально, а у меня нет.