[英]I am receiving a Server error on on the controller on my ASP.NET MVC app
I have an ASP.NET MVC application that I have created.我有一个我创建的 ASP.NET MVC 应用程序。 The data displays fine however I get an error which you can see below:数据显示正常,但是我收到一个错误,您可以在下面看到:
I have created the views and controllers fine however on 2 out of the 5 views / index there is an issue when performing a search via the controller I get an error.我已经很好地创建了视图和控制器,但是在 5 个视图/索引中的 2 个上,通过 controller 执行搜索时出现问题,我收到错误消息。
Below is the search functionality I have added to the controller以下是我添加到 controller 的搜索功能
public AppSupportEntities db = new AppSupportEntities();
// GET: Servers
public ActionResult Index(string searchBy, string search)
{
if (searchBy == "NAME")
{
return View(db.Servers.Where(x => x.NAME.StartsWith(search) || search == null).ToList());
}
else
{
return View(db.Servers.Where(x => x.DESCRIPTION.StartsWith(search) || search == null).ToList());
}
}
This is the search functionality added to the index page on the view这是添加到视图索引页面的搜索功能
@model IEnumerable<ADSTrepo.Models.Server>
@{
ViewBag.Title = "Index";
}
<h2>Server List</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<p>
@using (Html.BeginForm("Index", "Server", FormMethod.Get))
{
<b>Search By:</b> @Html.RadioButton("searchBy", "Name") <text>Name</text>
@Html.RadioButton("searchBy", "Description") <text>Description</text>
@Html.TextBox("Search")<input type="submit" value="Search" />
}
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.NAME)
</th>
<th>
@Html.DisplayNameFor(model => model.DESCRIPTION)
</th>
<th></th>
</tr>
@if (Model.Count() == 0)
{
<tr>
<td colspan="2"> No rows match the search criteria please try again</td>
</tr>
}
else
{
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.NAME)
</td>
<td>
@Html.DisplayFor(modelItem => item.DESCRIPTION)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}
}
</table>
Any help is greatly appreciated I must be missing something obvious however the views and controllers seem fine and the same as the others that are working非常感谢任何帮助我必须遗漏一些明显的东西但是视图和控制器看起来很好并且与其他正在工作的控制器相同
This has been resolved now.现在这个问题已经解决了。 The searchy by name in my controller was different to whats in my view.我的 controller 中的搜索名称与我认为的不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.