【发布时间】:2013-02-06 04:26:08
【问题描述】:
在我看来,我使用的是Html.BeginForm。在其中我有两个元素,当我设置 clic 时,应该提交表单,但我需要添加一个额外的字符串参数。
@using (Html.BeginForm("Index", "Quiz", FormMethod.Post, new { id = "form" }))
{
...
}
[HttpPost]
public ActionResult Index(string parameter, QuizCompletedViewModel q) //FormCollection f)
{
...
if (button.Equals("d"))
{
...
return RedirectToAction("ShowResults", new { testId = Quiz.QuizId, answeredTest = answeredId });
}
else
{
...
return RedirectToAction("Index", "Dashboard");
}
}
所以,在我的 jquery 函数中,我使用了 $("#element").submit() 并且参数 parameter 始终为空(这很正常)。如何使用 JQUERY 为 parameter 添加其他数据?
注意:我没有使用 AJAX。
【问题讨论】:
-
还有什么数据?从哪里?什么是
#element- 表单或其他元素? -
你如何通过模型?
-
@BhushanFirake 使用与我的剃须刀视图相同的整个模型
-
@tvanfosson #element 是表单,抱歉。我的意思是传递这样的数据: { parameter: "d", q: $("#form").serialize() }
标签: c# jquery asp.net-mvc jquery-ui asp.net-mvc-4