你應該使用ViewModel來實現這一點,以及一個強類型的View。像這樣的東西會工作:
public class StudentInformation
{
public string StudentName { get; set; }
public string TeacherName { get; set; }
public string CourseName { get; set; }
public string AppointmentDate { get; set; }
}
動作方法應該是這樣的:
public ActionResult MyFormLetter()
{
return View();
}
[HttpPost]
public ActionResult MyFormLetter(StudentInformation studentInformation)
{
// do what you like with the data passed through submitting the form
// you will have access to the form data like this:
// to get student's name: studentInformation.StudentName
// to get teacher's name: studentInformation.TeacherName
// to get course's name: studentInformation.CourseName
// to get appointment date string: studentInformation.AppointmentDate
}
還有一點查看代碼:
@model StudentInformation
@using(Html.BeginForm())
{
@Html.TextBoxFor(m => m.StudentName)
@Html.TextBoxFor(m => m.TeacherName)
@Html.TextBoxFor(m => m.CourseName)
@Html.TextBoxFor(m => m.AppointmentDate)
<input type="submit" value="Submit Form" />
}
當你到達從POST操作方法的提交,您將可以訪問輸入到表單視圖的所有數據。
免責聲明:查看代碼只顯示必要的元素,以顯示數據如何保存在模型綁定的模型中。
很好地完成。我不能用這種方式來說明。 – 2012-01-31 02:41:36
謝謝我的ViewModel。現在它工作正常。謝謝。 – CloudyKooper 2012-02-04 17:05:13