我的搜索返回null" 404页"

时间:2014-03-13 01:17:48

标签: c# asp.net-mvc sql-server-2008

我在MVC.Net C#上创建了搜索,并且我在下面使用了ADO.Net / SQL server 2008技术,我已经复制并粘贴了我的控制器页面&我的视图页面...你会善良并看看我的代码,并给我反馈,为什么这不会返回任何结果,但错误?提交搜索按钮时会发生此错误!

控制器:

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));
    }

和我的观点:

@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.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址并确保拼写正确

1 个答案:

答案 0 :(得分:1)

您可以尝试从

更改操作属性

发件人

[HttpGet]

[HttpPost]