在MVC中使用Post方法重定向到一个Action

在MVC中使用Post方法重定向到一个Action

问题描述:

我有两个表单提交按钮,一个用于搜索相应名称的记录,第二个用于在需要时进行更正后更新数据库中的记录。在MVC中使用Post方法重定向到一个Action

三人在控制器

  1. 编辑与HttpGet动作 - 当第一次视图中显示它从数据库加载所有的名字命名的下拉列表
  2. 编辑与HttpPost - 当我们点击搜索它取每那名
  3. EditPerson HttpPost的细节 - 当我们点击编辑记录它保存所有数据返回到DB

在代码中,我想这样做

public ActionResult EditOperation(string Command, DataLayer objmodel) 
{ 
    if (Command == "Search") 
    { 
     return RedirectToAction(Edit with Post method) // How to ? always going to Edit With get method 
    } 
    else if (Command == "Edit Record") 
    { 
     return RedirectToAction(EditPerson) //Easy to redirect but How to send Model object also ? 
    } 
    return View("Edit",objmodel); 
} 
RedirectToAction (String ActionName, String ControllerName , Object routeValues) 

,有没有办法告诉重定向到编辑行动编译但谁Post方法不是获取一个?
注意:不要想使用JavaScript在这里,只有纯粹的C#代码

+0

你可以注解只接受后动词的动作即[HttpPost],只有一个表单提交,我想知道你如何使用两个提交? –

+0

你想在表单中提交2个按钮吗?如果事情没有意义,那么表单只应该发布到操作方法。但是你可以修改'Edit'方法来包含保存记录例程,这取决于用户发送POST请求时提供的隐藏字段或其他字段值。 –

+0

多个提交按钮可以在一种形式中使用,但那不是我所关心的,我想重定向到具有特定方法的动作 – Saurabh

重定向总是用得到,试图返回“编辑”的观点,传递模型,你要使用:

public ActionResult Edit(){ 

....retrieve Model 

return View(MyModel); // default view : Edit 

} 

[HttpPost] 

public ActionResult Edit(MyModel){ 

....do things with MyModel 

return View("OtherView", MyModel); 

}