ASP.NET MVC在httpPost后返回Index视图

6

我创建了一个控制器中的两个视图。问题是,我希望在完成httppost后加载第二个视图。

索引视图

public ActionResult Index()
{
  return View();
}

HttpPost

[HttpPost]
public ActionResult Index(AccountModel model)
{

  return View("NEXTVIEW");

}

下一个视图

public ActionResult NEXTVIEW(EpmloyeeModal model)
{
  return View();
}

在HttpPost之后,我已经添加了返回到下一个视图的代码。然而它总是返回到Index视图。我尝试在不同的网站上寻找这样的场景,但是无处可找。
谢谢。
4个回答

19

试试这样做

[HttpPost]
public ActionResult Index(AccountModel model)
{
  return RedirectToAction("NEXTVIEW");
}

5

对于提交操作,请使用以下代码:

[HttpPost]
public ActionResult Index(AccountModel model)
{
   return RedirectToAction("NEXTVIEW");
}

哦,我回答晚了 ;( - Jeyhun Rahimov

5
您的下一个视图操作需要一个模型,您需要传递给它EmployeeModal模型。
[HttpPost]
public ActionResult Index(AccountModel model)
{
  return RedirectToAction("NEXTVIEW",new EpmloyeeModal());
}

4

对于发布内容,请使用以下方法:

[HttpPost]
public ActionResult Index(AccountModel model)
{
   return RedirectToAction("NEXTVIEW"); // Redirect to your NextView
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接