Hi Ruby888,
You can display search result in separate page by passing the view name.
Check this example. Now please take its reference and correct your code.
For this example i have used below article. You can get the Stored Procedure and follow the steps to Configuring and connecting Entity Framework to database.
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string customerName)
{
NorthwindEntities entities = new NorthwindEntities();
var searchResult = entities.SearchCustomers(customerName).Take(10).ToList();
return View("Details", searchResult);
}
}
View
Index.cshtml
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<input type="text" name="customerName" />
<input type="submit" name="btnSearch" value="Search" />
}
</div>
</body>
</html>
Details.cshtml
@model IEnumerable<_623158_Search_Result_New_Page.Customer>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Details</title>
</head>
<body>
<div>
<table>
<tr>
<th>CustomerID</th>
<th>Contact Name</th>
<th>Country</th>
</tr>
@foreach (Customer customer in Model)
{
<tr>
<td>@customer.CustomerID</td>
<td>@customer.ContactName</td>
<td>@customer.Country</td>
</tr>
}
</table>
<br />
@Html.ActionLink("Back", "Index", "Home")
</div>
</body>
</html>
Screenshot