我有一个Kendo标签条。每个选项卡上都有一个带有提交按钮的视图。我在处理多个提交按钮时遇到问题。我正在按照post的答案关注@mkozicki。
但我无法上班。这条线
var value = controllerContext.Controller.ValueProvider.GetValue(keyValue);
始终返回null。有人可以解释为什么这个答案不起作用或提供另一种方法来处理标签条中的多个提交按钮?
注意:
我也尝试过类似于此page的代码(我没有将我的原始来源添加为书签,但代码类似),但它并没有工作要么。
我尝试了两个AllowMultiple等于true和false,两个产品的结果相同:值为null
ClsActionMethodSelector.cs(创建多按钮属性)
[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(剑道标签条)
@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>