我的搜索返回null "页404"

本文关键字:quot 搜索 返回 我的 null | 更新日期: 2023-09-27 17:49:45

我已经创建了MVC搜索。Net c#和我正在使用ADO。Net/SQL server 2008技术在下面我复制并粘贴了我的控制器页面& &;我的View页面…你会是善良的,看看我的代码,给我反馈,为什么这不会返回任何结果,但一个错误?这个错误发生在我提交搜索按钮的时候!

控制器:

public class FormController : Controller
{
    Context db = new Context();

    [HttpGet]
    public ActionResult Report(string sortOrder, string currentFilter, string searchString, int? page) //adds a page parameter, a current sort order parameter, and a current filter parameter to the method 
    {
        ViewBag.CurrentSort = sortOrder;   // the view with the current sort order to keep the sort order the same while paging
        ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name_desc" : "";
        ViewBag.DateSortParm = sortOrder == "Date" ? "Date_desc" : "Date";
        if (searchString != null)
        {
            page = 1;  //maintain the filter settings during paging, and it must be restored to the text box when the page is redisplayed
        }
        else
        {
            searchString = currentFilter;
        }
        ViewBag.CurrentFilter = searchString;  // provides the view with the current filter strin

         var reports = from s in db.DRs
                      select s;
         if (!String.IsNullOrEmpty(searchString))
         {
             reports = db.DRs.Where(s => s.DR_REPORT_NUM.ToString().Contains(searchString.ToUpper())
                               || ...
         }
        #region Sorting
        switch (sortOrder)
        {
            case "Name_desc":
                reports = reports.OrderByDescending(s => s.DR_INM_LAST_NAME);
                break;
            case "Date":
                reports = reports.OrderBy(s => s.DR_INCIDENT_DATE);
                break;
            case "Date_desc":
                reports = reports.OrderByDescending(s => s.DR_INCIDENT_DATE); break;
            default: //Name ascending
                reports = reports.OrderBy(s => s.DR_INM_LAST_NAME);
                break;
        }
        #endregion

        int pageSize = 10;   // converts the inmate query to a single page of forms in a collection type that supports paging.
        int pageNumber = (page ?? 1);
        return View(reports.ToPagedList(pageNumber, pageSize));
    }

and my View:

@using (Html.BeginForm("Report", "Form", new { ReturnUrl = Request.QueryString["ReturnUrl"] }, FormMethod.Post))
{
    <p>
        <div style="width: 800px; margin: 0 auto;">
            <div style="width: 50%; float: left; margin-left: -5%" id="left">
                <h3>Find Report: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)<input type="submit" value="Search" /></h3>

'/'应用程序服务器错误。

资源找不到。描述:HTTP 404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下URL,并确保拼写正确

我的搜索返回null "页404"

您可以尝试从

更改action属性

[HttpGet]

[HttpPost]