I am trying to implement search functionality in MVC view. I have view called 'ReturnResults' and partial view (_Find) in it. _Find is object that I use to find/filter results.
Is this the correct way to implement search? I am getting error The model item passed into the dictionary is of type 'MyModels.ReturnResults', but this dictionary requires a model item of type 'MyModels.Find'.
Controller Method:
public ActionResult Locate(Find find)
{
List<ReturnResults> returnV = new List<ReturnResults>();
returnV = CallDB.GetList(find)
return View(returnV);
}
View (ReturnResults):
@model MyModels.ReturnResults
@{
ViewBag.Title = "List Results";
}
@Html.Partial("_Find", Model)
Partial View (_Find):
@model MyModels.Find
@{
ViewBag.Title = "Find";
}
@using (Html.BeginForm("Locate", "LocateCource", FormMethod.Post, new { name = "frmLocate", id = "frmLocate"}))
{
<td>
@Html.LabelFor(m => m.Number)
@Html.TextBoxFor(m => m.Number)
</td>
<td>
@Html.LabelFor(m => m.Course)
@Html.TextBoxFor(m => m.Course)
</td>
<td>
@Html.LabelFor(m => m.Location)
@Html.TextBoxFor(m => m.Location)
</td>
</td>
<td>
@Html.LabelFor(m => m.Condition1)
@Html.TextBoxFor(m => m.Condition1)
</td>
<td>
@Html.LabelFor(m => m.Condition2)
@Html.TextBoxFor(m => m.Condition2)
</td>
<td>
@Html.LabelFor(m => m.Condition3)
@Html.TextBoxFor(m => m.Condition3)
</td>
}
Partial View:
public class Find
{
[Display(Name = "Number ")]
public int Number { get; set; }
[Display(Name = "Course Name")]
public string Course { get; set; }
[Display(Name = "Course Name")]
public string Location { get; set; }
[Display(Name = "Condition1")]
public string Condition1 { get; set; }
[Display(Name = "Condition2")]
public string Condition3 { get; set; }
[Display(Name = "Condition3")]
public string Condition3 { get; set; }
}
View: (with Partial View)
public class ReturnResults
{
[Display(Name = "Number ")]
public int Number { get; set; }
[Display(Name = "Course Name")]
public string Course { get; set; }
[Display(Name = "Return1")]
public string Return1 { get; set; }
[Display(Name = "Return2")]
public string Return2 { get; set; }
[Display(Name = "Return3")]
public string Return3 { get; set; }
[Display(Name = "Return4")]
public string Return4 { get; set; }
[Display(Name = "Return5")]
public string Return5 { get; set; }
[Display(Name = "Return6")]
public string Return6 { get; set; }
}