ASP.Net MVC 4窗体与2提交按钮操作
发布时间:2023-02-17 10:56:04 所属栏目:asp.Net 来源:互联网
导读:我有一个表单在ASP.Net和剃刀。 我需要两种方式提交表单:一种是通过编辑操作,另一种是通过验证操作。 我应该怎么做呢? 我不介意使用JavaScript。 编辑: 使用自定义属性我得到这个错误。 The current request for action Resultados on controller type I
我有一个表单在ASP.Net和剃刀。 我需要两种方式提交表单:一种是通过编辑操作,另一种是通过验证操作。 我应该怎么做呢? 我不介意使用JavaScript。 编辑: 使用自定义属性我得到这个错误。 The current request for action ‘Resultados’ on controller type ‘InspecoesController’ is ambiguous between the following action methods: System.Web.Mvc.ActionResult Validar(System.Collections.Generic.ICollection1[Waveform.IEP.Intus.Server.Web.viewmodels.Resultadoviewmodel]) on type Waveform.IEP.Intus.Server.Web.Controllers.InspecoesController System.Web.Mvc.ActionResult Resultados(System.Collections.Generic.ICollection1[Waveform.IEP.Intus.Server.Web.viewmodels.Resultadoviewmodel]) on type Waveform.IEP.Intus.Server.Web.Controllers.InspecoesController 解决方法 这就是我们在我们的应用程序: 属性 public class HttpParamActionAttribute : ActionNameSelectorAttribute { public override bool IsValidName(ControllerContext controllerContext,string actionName,MethodInfo methodInfo) { if (actionName.Equals(methodInfo.Name,StringComparison.InvariantCultureIgnoreCase)) return true; var request = controllerContext.RequestContext.HttpContext.Request; return request[methodInfo.Name] != null; } } 用它装饰的动作: [HttpParamAction] public ActionResult Save(MyModel model) { // ... } [HttpParamAction] public ActionResult Publish(MyModel model) { // ... } HTML /剃刀 @using (@Html.BeginForm()) { <!-- form content here --> <input type="submit" name="Save" value="Save" /> <input type="submit" name="Publish" value="Publish" /> } 提交按钮的名称属性应该匹配操作/方法名称 这样你不必在JavaScript中硬编码url (编辑:十堰站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 在WebForms中调试时关闭捆绑/缩小
- asp.net-mvc – ASP.Net MVC:如何根据原始的Json数据创建一
- 在ASP.NET中,什么决定了HostingEnvironment.IsDevelopmentE
- 如何利用ASP.net IIS 7.5中的浏览器缓存
- asp.net – 如何扩展aspnet成员身份验证表?
- asp.net-mvc-3 – 如何在ASP.NET MVC中创建递归结构
- asp.net – Html.Partial()跳过控制器动作
- asp.net-mvc – 从Api控制器内生成绝对的url to action
- ASP.NET页面在IE缓存的清除办法
- asp.net-mvc-3 – ASP.Net MVC 3:在哪里处理会话丢失?
推荐文章
站长推荐
- asp.net-mvc-2 – 如何在ASP.NET MVC2中为Html.L
- asp.net-web-api – WebAPI 2属性路由启用会话状
- asp.net – NHibernate – ManagedWebSessionCon
- asp.net-mvc – 将DropDownListFor绑定到字典
- asp.net – 允许服务器/ usercontrol上的任何属性
- asp.net-mvc – 如何在asp.net中使用mvc构建购物
- asp.net-mvc – 如何编辑表格数据(ASP MVC)
- asp.net – 应用程序池循环如何影响ASP Net会话状
- asp.net读取excel文件的三种方法示例
- ASP.NET:预编译文件的文件名生成规则
热点阅读