您可以在表单中的隐藏变量中设置 Querystring 值,并在 GET 操作方法中呈现,并在 POST 操作方法中接受它。
GET
由您的操作呈现的视图
@using (Html.BeginForm())
{
//Other form elements also
@Html.Hidden("teacher",@Request.QueryString["teacherID"] as string)
@Html.Hidden("createAndAssign",@Request.QueryString["createAndAssign"]
as string)
<input type="submit" />
}
现在teacher
在您的操作方法中有一个参数和 createAndAssign 参数,HttpPost
以便在您提交表单时可用。
[HttpPost]
public ActionResult Create(string teacher,string createAndAssign)
{
//Save and Redirect
}
如果你的视图是强类型的(这是我个人的偏好),这很容易,
public ActionResult GET(string teacherID,string createdAndAssing)
{
var yourVMObject=new YourViewModel();
yourVMObject.TeacherID=teacherID;
yourVMObject.CreateAndAssign=createdAndAssing;
return View(createdAndAssing);
}
在你的强类型视图中,
@model YourViewModel
@using (Html.BeginForm())
{
//Other form elements also
@Html.HiddenFor(x=>x.TeacherID)
@Html.HiddenFor(x=>x.CreateAndAssign)
<input type="submit" />
}
在你的POST
行动中
[HttpPost]
public ActionResult Create(YourViewModel model)
{
//look for model.TeacherID
//Save and Redirect
}