Questions tagged [controller-action]

51 questions
40
votes
6 answers

How to serve html file from another directory as ActionResult

I have a specialised case where I wish to serve a straight html file from a Controller Action. I want to serve it from a different folder other than the Views folder. The file is located in Solution\Html\index.htm And I want to serve it from a…
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228
20
votes
4 answers

Html.Action - Get versus Post

I do this very often:
@Html.Action("Create", "Product")
it's convenient because I can delegate the painting of a product creation form to another controller action for embedding in places. However, I'm having issues in…
ekkis
  • 9,804
  • 13
  • 55
  • 105
12
votes
7 answers

Enforce Action Filter on all Controller Actions (C# / ASP.NET MVC)

I made a new action filter (attribute, similar to [Authorize]) which authorizes access to a controller action based on a session value. However, I'm basically decorating all my controller actions with that attribute (with the exception of very few).…
Alex
  • 75,813
  • 86
  • 255
  • 348
11
votes
2 answers

ASP.NET MVC: Enforce AJAX request on an action

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()) …
Remus
  • 1,433
  • 3
  • 14
  • 24
10
votes
4 answers

How to unit test whether a Core MVC controller action calls ControllerBase.Problem()

We have a controller that derives from ControllerBase with an action like this: public async Task Get(int id) { try { // Logic return Ok(someReturnValue); } catch { return Problem(); } } We also have a unit…
Martijn
  • 739
  • 9
  • 26
10
votes
3 answers

How to customize edit and update action in rails_admin

I'm using rails_admin and I think it's great. Unfortunately I can't get to override a specific action on a specific model. I just need to override edit and update behavior on one model. Any idea?
8
votes
3 answers

ASP.NET MVC 4: Only allow one request at a time

In my ASP.NET MVC Application, I want to handle all requests sequentially; no action/controller code should be executed concurrently with another. If two requests come in at similar times, it should run the first one first, then the second one when…
8
votes
3 answers

Starting and Forgetting an Async task in MVC Action

I have a standard, non-async action like: [HttpPost] public JsonResult StartGeneratePdf(int id) { PdfGenerator.Current.GenerateAsync(id); return Json(null); } The idea being that I know this PDF generation could take a long time, so I just…
6
votes
1 answer

How to use Custom AuthorizeAttribute for controller utilizing parameter value?

I am trying to secure a controller action to prevent a user from accessing an Entity that they do not have access to. I am able to do this with the following code. public ActionResult Entity(string entityCode) { if…
RSolberg
  • 26,821
  • 23
  • 116
  • 160
5
votes
2 answers

Rails: Custom nested controller actions

I want to setup a custom nested controller actions but I can't figure out the routing. I keep getting the following error No route matches [GET] "/assets" routes.rb resources :companies do resources :requests do match :accept …
4
votes
1 answer

RedirectToAction redirects with query parameters?

I am working on a ASP.NET MVC application and have ran in to a strange thing. I got two controller actions like this: [CustomAuthorize(Roles = SiteRoles.Admin)] public ActionResult Review(int? id) [CustomAuthorize(Roles =…
Banshee
  • 15,376
  • 38
  • 128
  • 219
4
votes
3 answers

Call a controller in another module from another controller

Yii::$app->runAction('new_controller/new_action', $params); I believe this can be used to call a controller action from another controller. Is there a way to call a controller action that resides in another module? Something…
DGT
  • 391
  • 1
  • 3
  • 13
4
votes
1 answer

Do AngularJS Controllers ever use more than one action/setup method?

Most of the examples of AngularJS controllers that I have seen, usually have a single action method that wires everything up for the view. On the other hand, in controllers that use the MVC pattern, rather than AngularJS's MVW, there are usually…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
3
votes
1 answer

How do I use CoffeeScript in Rails?

In my controller's create action, I have the following: def create @article = Article.find(params[:id]) respond_to do |format| if @comment.save format.js { render 'success.js' } else format.js { render 'failed.js' } end …
zolter
  • 7,070
  • 3
  • 37
  • 51
3
votes
2 answers

Using a .NET MVC Controller Action as the Source for an HTML

I'm trying to display the picture associated with a user in my database (the picture field's data type is image) on a page - unfortunately the code below fails to do that. HTML Controller Action public byte[]…
Jimbo
  • 22,379
  • 42
  • 117
  • 159
1
2 3 4