根据单击的按钮将相同的表单发布到不同的操作

我在StackOverflow上有类似的post,但也许我的误解更为重要。 我有一个动作索引()和索引视图的渲染。 从Index()视图取决于单击的按钮[HttpPost]索引()或[HttpPost] Search()必须调用因为我发布了一些数据。 发布到不同操作的唯一方法是使用jQuery吗? 如果jQuery是唯一的方法,如果我的操作返回视图(完整的Html页面),我必须从$ .post清理整个文档元素并用我的视图html填充它? 我对这一切都很陌生,非常感谢!

@using (Html.BeginForm()) {  ... ... } public ActionResult Index(string lang) { return View(); } //Perhaps this action is needed [HttpPost] public ActionResult Index(string lang, string startDate) { return View(); } [HttpPost] public ActionResult Search(string lang, string startDate) { return View(); ] 

您可以根据单击的按钮更改表单的操作属性。

例如,点击“go”按钮后发布到“搜索”操作:

 $('#go_button').click(function() { $('form').attr("action", "Search"); //change the form action $('form').submit(); // submit the form }); 

当您需要更改操作以及Controller时,除了已接受的答案之外:

 $('#go_button').click(function() { $('form').attr("action", "@("Search","OtherControllerName")"); //change the form action $('form').submit(); // submit the form });