MVC4基於模型視圖控制器設計,因此PageLoad()方法並不適用。
相關情況例如,你可能會尋找這是
型號
public class SampleModel
{
public int ModelId {get; set;}
public string ModelName {get; set;}
}
控制器
[HttpGet]
public ActionResult SampleController()
{
return View();
}
[HttpPost]
public ActionResult SampleController(SampleModel model)
{
//put code here to send to database
return View(model);
}
查看
@model YourProject.Models.SampleModel
@using (Html.BeginForm())
{
@Html.LabelFor(model => model.ModelId)
@Html.TextBoxFor(model => model.ModelId)
<br />
@Html.LabelFor(model => model.ModelName)
@Html.TextBoxFor(model => model.ModelName)
<input type="submit" value="submit" />
}
您正在閱讀的錯誤類型教程。您應該瞭解MVC,而不是WebForms。答案是會議或隱藏的輸入。 – SLaks