下面,在 CreateTest 中,一旦成功,我想从 CreateTest 重定向到测试。
我想做如下事情:
public ActionResult Tests(int ID, string projectName)
{
TestModel model = new TestModel (ID, projectName);
return View(model);
}
[HttpPost]
public ActionResult CreateTest(TestModel model)
{
try
{
return RedirectToAction("Tests");
}
catch (Exception e)
{
ModelState.AddModelError("Error", e.Message);
return View(model);
}
}
最佳答案
您可能需要在重定向时提供参数:
return RedirectToAction("Tests", new {
ID = model.ID,
projectName = model.ProjectName
});
你将重定向到的 url 现在看起来像这样:
/Foo/Tests?ID=123&projectName=abc
关于asp.net-mvc - 如何在不传递参数的情况下重定向到带有其他 Action 参数的 Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5101919/