所以,我試圖在列表頁面(http://example.com:3480/List)上提交一個實際上是Search實現的表單。到目前爲止,我已經做到了這一點:如何在MVC3中連接一個表單與控制器?
index.cshtml
@using(Html.BeginForm("Search","ListController"))
{
<input id=query type=text name=query />
<input id=btnsearch type=submit value=Search />
}
ListController.cs
[HttpPost]
public ActionResult Search(FormCollection collection)
{
Response.Write("We are here");
// Get Post Params Here
string var1 = collection["query"];
Response.Write(var1);
return View();
}
的Global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Details",
"Details/{id}/{orderid}",
new { controller = "Details", action = "Index", id = UrlParameter.Optional, orderid = UrlParameter.Optional }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
}
點擊它去http://example.com:3480/ListController/Search
這似乎很好。
現在我想我需要在Global.aspx中定義路由,但不確定。我想要的是在相同的View文件中顯示結果,而不是創建一個新的結果。
在這個時刻,我無法進入Search
方法發帖時
一個新的視圖? – MikeSW
@MikeSW用於測試,檢查我是否使用正確的方法發送 – Volatil3
*現在我沒有被髮送到正在發送數據的方法* - 以爲我的問題是誤導性的,我想添加此評論。 –