这主要是基于Maarten
Balliauw的帖子和评论的,基于属性的多属性按钮解决方案。
[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; }}
剃刀:
<form action="" method="post"> <input type="submit" value="Save" name="action:Save" /> <input type="submit" value="Cancel" name="action:Cancel" /></form>
和控制器:
[HttpPost][MultipleButton(Name = "action", Argument = "Save")]public ActionResult Save(MessageModel mm) { ... }[HttpPost][MultipleButton(Name = "action", Argument = "Cancel")]public ActionResult Cancel(MessageModel mm) { ... }
更新: 剃刀页面看起来可以提供相同的功能。对于新开发,它可能是更可取的。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)