Questions tagged [actionmethod]

Action methods typically have a one-to-one mapping with user interactions. Examples of user interactions include entering a URL into the browser, clicking a link, and submitting a form. Each of these user interactions causes a request to be sent to the server. In each case, the URL of the request includes information that the MVC framework uses to invoke an action method.

Most action methods return an instance of a class that derives from ActionResult. The ActionResult class is the base for all action results. However, there are different action result types, depending on the task that the action method is performing. For example, the most common action is to call the View method. The View method returns an instance of the ViewResult class, which is derived from ActionResult.

You can create action methods that return an object of any type, such as a string, an integer, or a Boolean value. These return types are wrapped in an appropriate ActionResult type before they are rendered to the response stream.

135 questions
5
votes
1 answer

Passing multiple parameter via GET with params keyword to an MVC controller action

Is there any way to pass multiple paramters by using params keyword to an action method with GET as below? http://.../Method/param1/param2/param3/..../paramN Action method should be as below: public ActionResult Method(params string[]…
Halil Ibrahim
  • 1,339
  • 1
  • 20
  • 39
5
votes
1 answer

Action method being called multiple times

I've just spotted something quite strange about an action method that is being called, via a simple click of a link, in my MVC 3 site. For some reason this action method is being called multiple times. Not only that but subsequent calls get called…
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
5
votes
4 answers

MVC button click to action

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 Kainth
  • 45,256
  • 81
  • 201
  • 304
4
votes
2 answers

MVC 3 Ajax Loading Icon when navigating to a new page/action method

I have been searching extensively on how to create a navigation link that will display an ajax Loading icon while the action method is running in MVC 3 using the Razor view engine. While I have found plenty of information regarding adding a loading…
Chad LaCroix
  • 161
  • 1
  • 7
3
votes
1 answer

Does a controllers non asynchronous method stop other users from entering when in use or locked?

I have a newbie question about controller methods in ASP.Net Core. I have the two different implementations below, one is synchronous and the other is asynchronous. Question - I understand the difference between sync and async, I think, but when it…
chuckd
  • 13,460
  • 29
  • 152
  • 331
3
votes
5 answers

.NET MVC: How to redirect response within a helper method

I have some code which is common to a number of my controller actions pulled out into a private "helper" method just for consolidation. The method is expected to "get" an object for me, though it performs some sanity/security checks and could…
3
votes
2 answers

Security concerns when using Html.Action to call [ChildActionOnly] action method

I have the following action method inside asp.net mvc5, which i define as ChildActionOnly:- [ChildActionOnly] public ActionResult GetChildRecords(int customerid) and i am calling it as follow, within my view:-
@Html.Action("GetChildRecords",…
3
votes
2 answers

Implementing Routes for dynamic actions in MVC 4.0

Is it possible to define a route in MVC that dynamically resolves the action based on part of the route? public class PersonalController { public ActionResult FriendGroup() { //code } public ActionResult RelativeGroup() { …
3
votes
3 answers

Handling 2 buttons submit Actions in a single View/Form - ASP.NET MVC 2 RTM

I have a View in which the user is able to upload a file to the server. In this view I also have 2 buttons: one to Upload a file and other to Download the last file imported. In my Controller I created 2 action methods: Import and Export. How could…
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
3
votes
3 answers

Dependency Injection into an MVC action method

I'm wondering if this is possible. I have a typical MVC action method with a signature that looks like this: public ActionResult View(MyModel model) { IAnObject myObject = new AnObject(); //several lines of code follow..... return…
larryq
  • 15,713
  • 38
  • 121
  • 190
2
votes
1 answer

What is the best way of calling an action method from another controller?

What is the best way to invoke an Action-method method in Controller A, from Action-method method in Controller B? Is it true to have such an invocation at all?
A.Dara
  • 784
  • 10
  • 23
2
votes
1 answer

Why is the MVC action method selector not choosing my HttpPut action?

Given the following route: context.MapRoute(null, "widgets", new { controller = "Widgets", action = "Add" }, new { httpMethod = new HttpMethodConstraint("PUT") }); And the following controller: public class WidgetsController { …
danludwig
  • 46,965
  • 25
  • 159
  • 237
2
votes
0 answers

In rails, the controller.action_methods returns methods even if they have no associated routes

For resourceful controllers, calling the controller.action_methods is yielding all the possible action methods on the controller. I have a resource for which I have restricted the routes to [:only=> "index"]. I am looking for a method similar to…
Tabrez
  • 3,424
  • 3
  • 27
  • 33
2
votes
1 answer

How to protect certain actions from usage according to a custom UserRoles table I created

This is the basic database structure for Users and UserRoles. My client wants to be able to look at a Role and tick some boxes, "This role can do x, y and z". X, Y and Z being some actions in the application. This isn't a new idea, and I'm sure…
Only Bolivian Here
  • 35,719
  • 63
  • 161
  • 257
2
votes
1 answer

ModelState.IsValid always returns true

I have the following action method: public ActionResult SignUp(Player player) { if (ModelState.IsValid) {...} } The problem is that ModelState.IsValid always returns true even if I have errors in my Player model. In the Player…
Zoliqa
  • 1,015
  • 2
  • 15
  • 36
1
2
3
8 9