I have a Kendo tab strip. On each tab is a view with a submit button. I'm having trouble handling multiple submit buttons. I'm following the answer on this post by @mkozicki.
But I can't get to work. The line
var value = controllerContext.Controller.ValueProvider.GetValue(keyValue);
always returns null. Can someone either explain why this answer doesn't work or provide another way of handling multiple submit buttons within a tab strip?
Notes:
I also tried code similar to what's at this page (I didn't bookmark my original source, but the code is similar), but it didn't work either.
I tried both AllowMultiple equals true and false, both product the same result: the value was null
ClsActionMethodSelector.cs (creates the multiple button attribute)
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MultipleButtonAttribute : ActionNameSelectorAttribute
{
public string Name { get; set; }
public string Argument { get; set; }
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
{
var isValidName = false;
var keyValue = string.Format("{0}:{1}", Name, Argument);
var value = controllerContext.Controller.ValueProvider.GetValue(keyValue);
if (value != null)
{
controllerContext.Controller.ControllerContext.RouteData.Values[Name] = Argument;
isValidName = true;
}
return isValidName;
}
}
AdminCustomerEdit.cshtml (the Kendo tab strip)
@using (Html.BeginForm("AdminCustomerEdit", "Admin", new {compI = ViewBag.compId}))
{
@(Html.Kendo().TabStrip()
.Name("AdminCustomerEditTabs")
.Items(items =>
{
items.Add()
.Text("Notes")
.HtmlAttributes(new {@class = "tab"})
.Content(Html.Action("AdminCustomerNotes", "Admin", new {customerID = Model.CompID}).ToString())
.ContentHtmlAttributes(new {@class = "tab-content"});
items.Add()
.Text("Contracts")
.HtmlAttributes(new { @class = "tab" })
.Content(Html.Action("AdminCustomerContracts", "Admin", new { customerID = Model.CompID }).ToString())
.ContentHtmlAttributes(new { @class = "tab-content" });
})
)
}
AdminController.cs
[HttpPost]
[MultipleButton(Name = "action", Argument = "CustomerNotes")]
public ActionResult AdminCustomerNotesSubmitEdit(CompanyNotes model)
{
return Redirect(Request.UrlReferrer.ToString());
}
[HttpPost]
[MultipleButton(Name = "action", Argument = "CustomerContracts")]
public ActionResult AdminCustomerContracts(CompanyContracts model)
{
return Redirect(Request.UrlReferrer.ToString());
}
AdminCustomerContractsEdit.cshtml
<button id="buttonContractsSave" type="submit" value="ContractsSave" name="action:CustomerContracts">Save</button>
AdminCustomerNotesEdit.cshtml
<button id="buttonNotesSave" type="submit" value="NotesSave" name="action:CustomerNotes">Save</button>