用
標記包裝所有輸入。 你可以使用HTML標記或者 ASP.NET MVC helper @Html.BeginForm(...) 來完成它。 提交表單后,所有輸入數據都將發送到控制器操作。 請參見一個示例:視圖:@using (Html.BeginForm("Search","Events"))
{
@Html.TextBox("name")
}
控制器:public class EventsController: Controller
{
public ActionResult Search(string name)
{
//do something
return View();//return"Search" view to the user
}
}
如果你需要使用更複雜的類型,只需lern如何在 ASP.NET MVC中使用模型。 下面是一個簡單的示例:
模型( C# ):public class UserModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
視圖:@model UserModel
@using (Html.BeginForm("Search","Events"))
{
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
}
控制器:public class EventsController: Controller
{
public ActionResult Search(UserModel model)
{
//do something
return View();//return"Search" view to the user
//return View(model);//You can also return view with the model to the user
//return View("SpecificView");//You can specify a concrete view name as well
}
}