actionmethod

MVC button click to action [duplicate]

懵懂的女人 提交于 2019-11-30 15:41:22
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Mvc Html.ActionButton With ASP.NET MVC 3 I know how to create a link to an action method very easily but what I'd like to know is how do you make a button (when clicked) call a particular action method? 回答1: Sachin, If you're using jquery (which you don't mention but I'll show as it's fairly standard with mvc), you'd do the following: $('#buttonId').click(function(){ document.location = '@Url.Action("MyAction",

MVC button click to action [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-11-30 15:11:53
Possible Duplicate: Mvc Html.ActionButton With ASP.NET MVC 3 I know how to create a link to an action method very easily but what I'd like to know is how do you make a button (when clicked) call a particular action method? Sachin, If you're using jquery (which you don't mention but I'll show as it's fairly standard with mvc), you'd do the following: $('#buttonId').click(function(){ document.location = '@Url.Action("MyAction","MyController")'; }); of course, you'd probably want to use ajax, but this is a basic example. You could use an html <form> : @using (Html.BeginForm("SomeAction",

ASP.NET MVC: Enforce AJAX request on an action

可紊 提交于 2019-11-30 02:37:53
问题 I'm looking for a way to enforce a controller's action to be accessed only via an AJAX request. What is the best way to do this before the action method is called? I want to refactor the following from my action methods: if(Request.IsAjaxRequest()) // Do something else // return an error of some sort What I'm envisioning is an ActionMethodSelectorAttribute that can be used like the [AcceptVerbs] attribute. I have no experience crating such a custom attribute though. 回答1: Create an

What clever things have you done with an ASP.NET MVC Action method

半世苍凉 提交于 2019-11-28 15:23:43
The ASP.NET MVC controller action methods are primarily used for handling 'business' operations but it can be used for lots more. I thought it would be fun to see what creative, useful things people have created actions for that may be practical or useful for others. Here's my contribution : Javascript file concatenator - to reduce number of http requests: [OutputCache(Duration = 5 * 60, VaryByParam="")] // DONT USE "None" here * public ContentResult RenderJavascript(){ StringBuilder js = new StringBuilder(); StringWriter sw = new StringWriter(js); // load all my javascript files js.AppendLine

How to invoke a bean action method using a link? The onclick does not work

南楼画角 提交于 2019-11-28 12:29:27
I'm trying to implement a list of users names which can be rearranged by clicking on UP or DOWN links. <ul> <ui:repeat var="user" value="#{cc.attrs.value}"> <li> #{user.name} <h:link outcome = "user" value = "left" onclick="#{accountController.moveDown}"> <f:param name="id" value = "${user.id}" /> </h:link> </li> </ui:repeat> </ul> The problem here is that it seems that I'm not using the onclick attribute correctly. What is the proper way for doing this? Edit: Following your advices I placed all the links in a form: <h:form> <ui:repeat value="#{cc.attrs.value}" var = "user"> <div class = "user

How to invoke a bean action method using a link? The onclick does not work

拜拜、爱过 提交于 2019-11-27 07:03:48
问题 I'm trying to implement a list of users names which can be rearranged by clicking on UP or DOWN links. <ul> <ui:repeat var="user" value="#{cc.attrs.value}"> <li> #{user.name} <h:link outcome = "user" value = "left" onclick="#{accountController.moveDown}"> <f:param name="id" value = "${user.id}" /> </h:link> </li> </ui:repeat> </ul> The problem here is that it seems that I'm not using the onclick attribute correctly. What is the proper way for doing this? Edit: Following your advices I placed

How to receive JSON as an MVC 5 action method parameter

大城市里の小女人 提交于 2019-11-26 15:12:41
I have been trying the whole afternoon crawling through the web trying to receive a JSON object in the action controller. What is the correct and or easier way to go about doing it? I have tried the following: 1: //Post/ Roles/AddUser [HttpPost] public ActionResult AddUser(String model) { if(model != null) { return Json("Success"); }else { return Json("An Error Has occoured"); } } Which gave me a null value on my input. 2: //Post/ Roles/AddUser [HttpPost] public ActionResult AddUser(IDictionary<string, object> model) { if(model != null) { return Json("Success"); }else { return Json("An Error