asp.net-mvc – 如何在ASP.NET MVC中执行辅助操作(即计算字段)?
发布时间:2020-12-15 23:56:10 所属栏目:asp.Net 来源:网络整理
导读:我需要对ASP.NET MVC View进行一些计算,这是一种与表单提交不同的操作.我已尝试过各种方法通过ActionLink将当前Model传递给新的控制器操作,但该模型似乎没有被传递. public ActionResult Calculate(MuralProject proj){ ProjectFormRepository db = new Proj
我需要对ASP.NET MVC View进行一些计算,这是一种与表单提交不同的操作.我已尝试过各种方法通过ActionLink将当前Model传递给新的控制器操作,但该模型似乎没有被传递.
public ActionResult Calculate(MuralProject proj) { ProjectFormRepository db = new ProjectFormRepository(); List<Constant> constants = db.GetConstantsByFormType(FormTypeEnum.Murals); proj.Materials = new MuralMaterials(); proj.Materials.Volunteers = this.GetVolunteerCount(constants,proj); this.InitializeView(); return View("View",proj); } 我的Html.ActionLink语法需要什么才能让我调用它并让返回的视图具有相同的模型数据(带有计算的更改)?或者,还有另一种方法可以实现这一目标吗? 我也试过一个Ajax.ActionLink方法,但我遇到了同样的问题 编辑:“为您的提交按钮命名,然后检查控制器方法中提交的值”方法显示here是我正在寻找的. 解决方法
[看到你的评论;我会在这里重新发布这个答案,这样你就可以将问题标记为已解决,并将其标记为社区wiki,这样我就不会得到代表 – Dylan]
为提交按钮指定名称,然后在控制器方法中检查提交的值: <% Html.BeginForm("MyAction","MyController",FormMethod.Post); %> <input type="submit" name="submitButton" value="Send" /> <input type="submit" name="submitButton" value="Cancel" /> <% Html.EndForm(); %> 张贴到 public class MyController : Controller { public ActionResult MyAction(string submitButton) { switch(submitButton) { case "Send": // delegate sending to another controller action return(Send()); case "Cancel": // call another action to perform the cancellation return(Cancel()); default: // If they've submitted the form without a submitButton,// just return the view again. return(View()); } } private ActionResult Cancel() { // process the cancellation request here. return(View("Cancelled")); } private ActionResult Send() { // perform the actual send operation here. return(View("SendConfirmed")); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- com – asp经典中的server.createObject和createobject之间
- asp.net – CompositeControl中的DropDownList是否应该记住
- asp.net – 存储DotNetOpenAuth信息和用户信息检索
- 是*不*使用asp.net成员资格提供程序一个坏主意?
- asp.net-mvc – Action方法中的routeValues不接受ExpandoOb
- asp.net-mvc – 如何在VS2008 Web Devloper Express中的一个
- asp.net-mvc – 在@ Html.ActionLink中放置@ Html.DisplayF
- asp.net-web-api – 用于自托管模式的WebApi按请求存储
- asp.net-mvc-3 – ASP.NET MVC3 – Html.TextBoxFor和autof
- ASP.NET用户未显示所有Active Directory组
推荐文章
站长推荐
- asp.net – 在部署到SharePoint时,ObjectDataSou
- asp.net-mvc-3 – @ Html.TextBoxFor文本框在验证
- asp.net – $(“#dialog”).parent().appendTo($
- ASP.Net:将客户端onClick添加到GridView中的Hyp
- asp.net – 如何在dotnetnuke网站上为global.asc
- asp.net-mvc – webgrid中的Mvc 3 texbox(razor)
- asp.net-mvc – 使用ASP.NET MVC和Razor的Knocko
- asp.net-mvc-4 – 使用Durandal的会话数据
- asp.net-mvc – Azure上的MVC4部署问题
- asp.net – 获取包含HTML标记的文本子字符串
热点阅读