-2

我有以下看法:

<h2>enter the student name to search</h2>

@using (Html.BeginForm())
{
  <label>Search:</label>
  <input type="text" name="searchString" />
  <input type="submit" name="submit" />
}

并且视图对应于以下控制器

namespace Searching.Controllers
{ 
   public class SearchController : Controller
   //somecode

   [HttpPost] 
   public ActionResult SearchIndex(FormCollection formCollection)
   {
      string searchString=formCollection["searchString"];
      var search = from m in db.Searches select m;
      if (!String.IsNullOrEmpty(searchString))
      {
        search = search.Where(s => s.Name.Contains(searchString));
      }
      return View(search);
    }
  }
}

控制器名称是 SearchController.cs,传递表单的方法名称是 SearchIndex。Html.BeginForm() 中的参数应该是什么。我是初学者。

4

1 回答 1

2
Html.BeginForm("SearchIndex", "Search", .....)

您应该阅读以下内容:http: //msdn.microsoft.com/en-us/library/dd410596.aspx

于 2012-05-04T10:42:34.863 回答