Hey guys i'm stuck on an issue and I searched the site before qnd found solutions but I can't seem to find the problem in my code. So I was hoping somebody more experienced could help me out here.
I want to put something into an input box on the main index.cshtml and then send it with to search for this input.
Home/index.cshtml from search onward is whats not working.
@model webApp.Models.Table
@{
ViewBag.Title = "Home Page";
}
<div class="jumbotron">
<h1>WebApp</h1>
</div>
<div class="row">
<div class="col-md-4">
<h2>Index</h2>
<p>
@Html.ActionLink("Database lisst", "Index", "Tables")<br/>
</p>
</div>
<div class="col-md-4">
<h2>Search</h2>
<p>
@using (Html.BeginForm("Search", "Tables", FormMethod.Post))
{
<p>
Email: @Html.TextBoxFor(model => model.email) <br />
<input type="submit" value="Filter" />
</p>
}
</p>
</div>
Search.cshtml
@model webApp.Models.Table
@{
ViewBag.Title = "Search";
}
<h2>Search</h2>
<div>
<h4>Table</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.email)
</dt>
<dd>
@Html.DisplayFor(model => model.email)
</dd>
<dt>
@Html.DisplayNameFor(model => model.code)
</dt>
<dd>
@Html.DisplayFor(model => model.code)
</dd>
</dl>
</div>
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
@Html.ActionLink("Back to List", "Index")
</p>
controller
public ActionResult Search(string emailString)
{
var search = from m in db.Table select m;
if (!String.IsNullOrEmpty(emailString))
{
search = search.Where(s => s.email.Contains(emailString));
}
return View(search);
}
I'm very inexperienced in mvc and asp.net so any help would be really nice.
EDIT: Forgot the mention the actual issue, I keep getting this error at the moment.
The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[webApp.Models.Table]', but this dictionary requires a model item of type 'webApp.Models.Table'.