我正在用ASP.NET MVC 4和C#創建一個站點。主頁面是一個帶有「搜索」標籤的提交按鈕的搜索欄。我希望用戶能夠輸入音樂藝術家並按下「搜索」按鈕。然後該網站應該帶着結果進入「結果」頁面。如何在按下提交按鈕後重定向到下一頁?
按下搜索按鈕後,我無法進入結果頁面。
我視圖Index.cshtml形式如下:
<form method="post" class="form-inline">
<div class="row">
<div class="col-md-1" style="min-width:300px">
<input type="text" name="Artist" class="form-control box-shadow--4dp" placeholder="Artist Name" />
</div>
<div class="col-md-2">
<input type="submit" class="btn btn-default box-shadow--4dp" value="Search" />
</div>
</div>
</form>
而我HomeController.cs類似於:
namespace Task2.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
// edit
[HttpPost]
public ActionResult Index(string Artist)
{
return RedirectToAction("Result", "Home");
}
public ActionResult Contact()
{
ViewBag.Message = "For more information you can contact me using the form below.";
return View();
}
public ActionResult Result(string Artist)
{
ViewBag.Message = Artist;
return View();
}
}
}
所以總結,哪能引起提交按鈕重定向用戶到結果頁面的結果?
謝謝!
[執行提交(回發)中並用ASP.net MVC重定向](的可能的複製http://stackoverflow.com/questions/9978348/performing-submitpostback-and-redirect-with-asp-net- mvc) –