**The problem is No webpage was found for the web address: https://localhost:7264/PosLajuParcel/SearchIndex?SearchString=6F62AF036B
im using Index.cshtml for return page and I also already tried change return Index to return Error but its like IAction function not being read at all. Idk what to do please helpp**
@model IEnumerable<MVC1405.Models.PosLajuParcel>
<html>
<head>
<title>Parcel List</title>
</head>
<body>
<h5>Parcel List</h5>
<p>
@Html.ActionLink("Create", "ParcelDelivery")
</p>
@using (Html.BeginForm("SearchIndex", "PosLajuParcel", FormMethod.Get))
{
<p>
<label>Search by parcel id or sender name</label>
@Html.TextBox("SearchString")
<input type="submit" value="Search" />
@Html.ActionLink("Back to Full List", "Index")
</p>
}
<table class="table">
<tr>
<th>@Html.DisplayNameFor(x => x.ViewId)</th>
<th>@Html.DisplayNameFor(x => x.ViewDateTime)</th>
<th>@Html.DisplayNameFor(x => x.SenderName)</th>
<th>@Html.DisplayNameFor(x => x.SenderPhone)</th>
<th>@Html.DisplayNameFor(x => x.ReceiverName)</th>
<th>@Html.DisplayNameFor(x => x.ReceiverAddress)</th>
<th>@Html.DisplayNameFor(x => x.ReceiverPhone)</th>
<th>@Html.DisplayNameFor(x => x.DictWeight)</th>
<th>@Html.DisplayNameFor(x => x.Amount)</th>
</tr>
@foreach (var x in Model)
{
<tr>
<td>@Html.DisplayFor(y => x.ViewId)</td>
<td>@Html.DisplayFor(y => x.ViewDateTime)</td>
<td>@Html.DisplayFor(y => x.SenderName)</td>
<td>@Html.DisplayFor(y => x.SenderPhone)</td>
<td>@Html.DisplayFor(y => x.ReceiverName)</td>
<td>@Html.DisplayFor(y => x.ReceiverAddress)</td>
<td>@Html.DisplayFor(y => x.ReceiverPhone)</td>
<td>@Html.DisplayFor(y => x.DictWeight[x.IndexWeight])</td>
<td>@Html.DisplayFor(y => x.Amount)</td>
<td>
@Html.ActionLink("Details", "Details", new { id = x.ViewId }) |
@Html.ActionLink("Edit", "Edit", new { id = x.ViewId }) |
@Html.ActionLink("Delete", "Delete", new { id = x.ViewId })
</td>
</tr>
}
</table>
</body>
</html>
and this is my controller action to handle this form:
IList<PosLajuParcel> GetDbList()
{
IList<PosLajuParcel> dbList = new List<PosLajuParcel>();
SqlConnection conn = new SqlConnection(configuration.GetConnectionString("ParcelConnStr"));
string sql = @"SELECT * FROM PosLajuParcels";
SqlCommand cmd = new SqlCommand(sql, conn);
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
dbList.Add(new PosLajuParcel()
{
ViewId = reader.GetString(0),
ViewDateTime = reader.GetDateTime(1),
SenderName = reader.GetString(2),
SenderAddress = reader.GetString(3),
SenderPhone = reader.GetString(4),
SenderEmail = reader.GetString(5),
ReceiverName = reader.GetString(6),
ReceiverAddress = reader.GetString(7),
ReceiverPhone = reader.GetString(8),
ReceiverEmail = reader.GetString(9),
IndexWeight = reader.GetInt32(10),
IndexZone = reader.GetInt32(11),
Amount = reader.GetDouble(12)
});
}
}
catch
{
RedirectToAction("Error");
}
finally
{
conn.Close();
}
return dbList;
}
public IActionResult SearchIndex(string SearchString = "")
{
IList<PosLajuParcel> dbList = GetDbList();
var result = dbList.Where(x => x.ParcelId.ToLower().Contains(SearchString.ToLower()) ||
x.SenderName.ToLower().Contains(SearchString.ToLower()))
.OrderBy(x => x.SenderName).ThenByDescending(x => x.ViewDateTime);
return View("Index", result);
}
I expecting it will display filtered data from database in the view table
New contributor
Naim Fitri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.