Questions tagged [controllercontext]
19 questions
22
votes
6 answers
What the heck is a context?
I'm starting to see Contexts everywhere I look. In ASP.NET MVC, there are ControllerContexts, RequestContexts, HttpContexts, FormContexts. In Entity Framework, you have ObjectContexts and DbContexts. Ninject has Ninject.Activation.IContext.
What…

Hobbes
- 370
- 2
- 7
15
votes
1 answer
ActionDescriptor from ControllerContext
Given I have access only to ControllerContext and not Action____Contexts what is the optimal way to get the current executing ActionDescriptor?
So far the only method I've found is:
new ReflectedControllerDescriptor(context.Controller.GetType())
…

Chris Marisic
- 32,487
- 24
- 164
- 258
8
votes
3 answers
How do I Unit Test Actions without Mocking that use UpdateModel?
I have been working my way through Scott Guthrie's excellent post on ASP.NET MVC Beta 1. In it he shows the improvements made to the UpdateModel method and how they improve unit testing. I have recreated a similar project however anytime I run a…

Doug Wilson
- 4,185
- 3
- 30
- 35
7
votes
1 answer
Unit testing method converting MVC view to string using View.Render method
I have written method that converts MVC view to string and test method to check if it returns string.
Of course it works with Web but when I run test in NUnit it throws a NullReferenceException in System.Web when method tries to call…

Mad Max
- 186
- 2
- 11
4
votes
1 answer
How do I stub the HttpSessionState in MVC RC1 with rhino mocks?
I'm trying to take advantage of the recent ControllerContext refactoring in asp.net mvc rc1. I should be able to stub the session rather simply but I keep getting a System.NullReferenceException on line 2 when running the following code:
var…

Dane O'Connor
- 75,180
- 37
- 119
- 173
4
votes
2 answers
Get Controller instance in AuthorizeAttribute Mvc Core Web Api
I had used below class to to control my api method request and setup some properties of BaseController class to use in methods commonly.
this one is from Asp.Net Mvc Web Api
using System;
using System.Collections.Generic;
using System.Linq;
using…

m3rt_ali
- 73
- 1
- 9
3
votes
2 answers
Controller equivalent of HttpContext.Current in ASP.NET MVC
I'd like to get access to the current executing Controller so I can offload the return of the appropriate ActionResult onto a helper method. To this end, I'm looking for the equivalent of what I would have thought would be ControllerContext.Current…

tags2k
- 82,117
- 31
- 79
- 106
3
votes
2 answers
How to mock a DisplayMode in ControllerContext For Unit Test c#
I want to test an action in my controller that use a controllerContext as a parameter to generate a pdf document based on a 3th part library "Rotativa".
Here is the implementation of the action (function) :
public ActionResult DetailsPrint(int?…

Le-Mr-Ruyk
- 179
- 2
- 17
3
votes
1 answer
Can I access the ViewData from the HttpContext?
Im working with a project that sets variables such as the current user profile object in its authorize action filter, storing them in the ViewData for access by the following action method.
The action method then calls functionality from the…

Jimbo
- 22,379
- 42
- 117
- 159
2
votes
1 answer
using ControllerContext.RequestContext in a web api controller
I am try to integrate SagePayMvc.dll into a ASP.NET Web API project which requires ControllerContext.RequestContext to be passed in order to form the Notification Url.
Currently I am experiencing some difficulties in achieving this, I need to pass…

CryoFusion87
- 796
- 1
- 8
- 28
1
vote
1 answer
Rotativa BuildFile not hitting the Action Method
I have two action methods in my Controller class:
DetailsAll: to get some data and display in the view
SaveAsPDF: Called on windows.load of DetailsAll.cshtml which should save DetailsAll view as pdf
My issue is in SaveAsPDF Action method. Here I…

Divya
- 11
- 3
1
vote
0 answers
Rotativa pdf generte issue after calling Action from another controller
Getting errro at ControllerContext after calling Action from another controller:-
var pdfBytes = new ViewAsPdf("MonthlyReport", GetOverAllSales)
{
PageWidth = 215.9,
PageHeight = 279.4,
…

R. Patel
- 19
- 4
1
vote
3 answers
Render a Razor view to string => ControllerContext is null when called from recurrent task
I'm using ASP.NET MVC3
I have a .cshtml view and I want to stringify it to be incorporated in an email body.
Here is the method I use :
//Renders a view to a string
private string RenderRazorViewToString(string viewName, object model)
{
…

AlexB
- 7,302
- 12
- 56
- 74
0
votes
1 answer
Testing Account/Logon Action
I'm testing the Account/Loggon action using the built-in testing tool of Visual Studio 2010 and the class library from this article to create a fake controller context.
When I run the test method, this code line:
…

davidson1988
- 51
- 3
- 7
0
votes
1 answer
The web API for Httpget request which read the data from the database
public async Task> ReadClassData()
{
var data = await _classdata.ReadClassData.TolistAsync();
var classData = data.Select(c => new tblclass
{
classId = c.classId,
…

owais ahmed
- 1
- 1