i have a kendo menu that is bound to my form by the onclick event like this
@(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"))
)
and in my form i have a hiden field called 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>
}
i want to set my field form (FormMode) with the selected menuitem text "New" or "Edit". I noticed that the onclick overrides the selected event. So.. It would be something like this
<script type="text/javascript">
$(function () {
$('#New').on('click', function () {
$("#FormMode").val($(this).text());
});
});
function select(e) {
}
But this does not work.. On the controler side i have
public ActionResult Create(CrBSfune p_BSfune)
{
(...)
if (p_BSfune.FormMode == "New")
return RedirectToAction("Create");
else
return RedirectToAction("Index");
}
But my p_BSfune.FormMode is null. Can you help? Thanks.:)
Got it!!! Catching the click event was the solution, the way to pass the value.. that was more trickie.. but after several attempts got it.:) did this and it works fine.:)
$('#New').click(function (e) {
e.preventDefault();
$('#FormCreate')[0].FormMode.value = e.target.innerText;
$('#FormCreate').submit();});
Don't know if it is the best approach.. but it works.:)