我在 StackOverflow 上有一篇类似的帖子,但也许我的误解更为严重。 我有一个 Action Index() 和一个 Index 查看它的渲染。 根据单击的按钮,从 Index() View 必须调用 [HttpPost]Index() 或 [HttpPost]Search() 因为我正在发布一些数据。发布到不同操作的唯一方法是使用 jQuery 吗?如果 jQuery 是唯一的方法,如果我的操作返回 View (完整的 Html 页面),我必须从 $.post 中清除整个文档元素并用我的 View html 填充它?我对这一切都很陌生,非常感谢!
@using (Html.BeginForm())
{
<input name="startDate" type="text" size="20" class="inputfield" id="datepicker" />
<a href="#" id="apply_button">...</a>
<a href="#" id="go_button">...</a>
}
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_button').click(function() {
$('form').attr("action", "Search"); //change the form action
$('form').submit(); // submit the form
});
关于javascript - 根据单击的按钮将相同的表单发布到不同的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7508233/