我有一个剑道菜单,通过这样的 onclick 事件绑定到我的表单
@(Html.Kendo().Menu()
.Name("MenuCreate")
.Items(items =>
{
items.Add().Text("<<").Action("Index", "BSfune");
items.Add().Text("New").HtmlAttributes(new{onclick = "getElementById('FormCreate').submit()", @id = "New"});
items.Add().Text("Edit").HtmlAttributes(new { onclick = "getElementById('FormCreate').submit()", @id = "Edit" });
})
.Events(e => e.Select("select"))
)
在我的表单中,我有一个名为 FormmMode 的隐藏字段
@using (Html.BeginForm("Create", "BSfune", FormMethod.Post, new { id = "FormCreate" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="form">
<fieldset>
<legend>@ViewBag.Title</legend>
<div>
<div>
(My form code)
</div>
@Html.HiddenFor(model => model.FormMode, new { @id = "FormMode"})
<br />
<br />
<br />
</div>
</fieldset>
</div>
}
我想用选定的菜单项文本“新建”或“编辑”设置我的字段表单(FormMode)。我注意到 onclick 覆盖了选定的事件。所以..会是这样的
<script type="text/javascript">
$(function () {
$('#New').on('click', function () {
$("#FormMode").val($(this).text());
});
});
function select(e) {
}
但这不起作用..在控制器方面我有
public ActionResult Create(CrBSfune p_BSfune)
{
(...)
if (p_BSfune.FormMode == "New")
return RedirectToAction("Create");
else
return RedirectToAction("Index");
}
但我的 p_BSfune.FormMode 为空。你能帮我吗?谢谢。:)