MVC :: Getting Controller And Action From HttpContext?

Mar 8, 2010

What's the correct way to get the controller name and action from an httpContext object? I can see the values in the debug, but I don't seem to be able to get to them in the object code?

View 13 Replies


Similar Messages:

Test That A Controller Action Simply Returns A Link To Another Action?

Apr 29, 2010

Lets say I have a simple controller for ASP.NET MVC I want to test. I want to test that a controller action (Foo, in this case) simply returns a link to another action (Bar, in this case).How would you test TestController.Foo? (either the first or second link)

My implementation has the same link twice. One passes the url throw ViewData[]. This seems more testable to me, as I can check the ViewData collection returned from Foo(). Even this way though, I don't know how to validate the url itself without making dependencies on routing.The controller:

public class TestController : Controller
{
public ActionResult Foo()[code].....

View 1 Replies

MVC :: Controller Invokes GET Action Instead Of POST Action

May 20, 2010

I'm trying to add file upload functionality to a page. I've got a form that posts the selected file to a controller with a 'savefile' method. But if I don't add a get version of 'savefile' I'll get a 404 error. Here is the form code which is presented on the Index page:

[Code]....

And here is the controller code:

[Code]....

Intuitively I don't think I should need a GET version of SaveFile but if omit it I get a 404 error when the form posts. Why should I need a GET version of SaveFile when all I want is to post a form and save the file?

View 4 Replies

MVC :: Get The Current Action / Controller Name In A Controller Or Class?

Mar 14, 2011

How do you get the current action / controller name in a controller or class?

i can't show it in my view but that's not what i want.

View 1 Replies

MVC :: Calling Action Of A Controller From Another Controller?

Jan 24, 2011

I have a User entity and a department entity. I have a UserViewModel and DepartmentListModel which has List of departments.

UserViewModel has a property of type DepartmentListModel .

Now on user/create action I need to populate DepartmentListModel by calling DepartmentController's list action. List action returns populated DepartmentListViewModel.

From UserController how do I set DepartmentListModel ?

I tried doing so

[Code]....

But RedirectToAction returns RediretToRouteResult

View 7 Replies

MVC :: Access HTTPContext And Session From Custom Base Controller Class?

Jan 13, 2010

I built a base controller class inherits from Controller class to add some custom behavior to all controllers which will inherit from this base class.

My issue is when I try to access HTTPContext and Session objects in my custom base class, they are always null.

Am I doing something wrong or need missing something?

My custom base class definition:

public class ApplicationControllerBase : Controller

controllers classes definition:

public class HomeController : ApplicationControllerBase

using ASP.NET MVC 1, .NET 3.5.

UPDATE:

It seems the issue is I try to access HTTPContext in the constructor while HTTPContext is not ready yet, I tried it in the OnActionExecuted event handler and it works fine.

My question is what is the best place to access Session object in my custom controller class, that will guarantee executing my code with all controllers.

View 3 Replies

How To Get The Id Value In Controller / Action / Id

Sep 24, 2010

I have an edit application view, and it can be found at the following URL:

http://localhost:17262/Application/EditApplication/1

1 equals the application ID.

Also on the page I have a link that goes to another view to add an assistant for the application. I want to pass it the application ID so that the new assistant can be "linked" to this application. How would I get the value of 1 and add it to my action link? This is what I have in my HTML so far:

<%: Html.ActionLink("Add New Assistant", "Create", "Assistant", new { applicationID = "id" }, null) %>

View 1 Replies

MVC :: One Action Per Controller?

Jul 9, 2010

If I have a controller with more than one action on, e.g. UserController, then I end up having that class require every dependency of every action. Is there a way I can have one controller per action and yet have the URLs appear the same way they currently do? e.g.MySite.com/User/Edit/1 would remap to User_EditController.Edit

View 1 Replies

Same Controller Action Being Invoked In Mvc

Jan 12, 2011

I am not sure what is going on but even though I am invoking a different controller with action a particular FooController's Index action is being invoked all the time. The Global.asax file has setup the FooController to be the default controller.

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "FooController", action = "SomeAction", id = UrlParameter.Optional } // Parameter defaults
);
}

View 1 Replies

.net - Aspx Url To Mvc Controller Action

Dec 17, 2010

I have an aspx page Test.aspx. It handles requests like

Test.aspx?First=value1&Second=value2&third=value3

How can I use routing to redirect this url to

TestController/MyAction?First=value1&Second=value2&third=value3

I know I can create an aspx and perform redirect in it`s page load. But seems ugly and I think it can be done with some custom route.What I`ve tried was: this solution.but it didnt work for me. I remember, that Test.aspx should not be on a disk. I don`t have it, and routing is still not working.

View 1 Replies

C# - Securing Controller Action In MVC?

Feb 2, 2010

In ASP.NET MVC 2, to secure controller action, i have created a class RequirePermission inherited from ActionFilterAttribute class. The controller action looks like

[Code]....

Now instead of making different attributes , I want to use RequirePermission attribute like
[RequirePermission(permissions=Permissions.CanView+","+Permissions.CanEdit)] so that i can use it for different scenerious. but the compiler throw the following error. An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

View 1 Replies

MVC :: How To Get An Action Link From Within The Controller

Dec 21, 2010

I know I can use Html.ActionLink(...) from my view to render an anchor tag with a link to an action. I know I can call RedirectToAction(...) from the controller to immediately call another action. But what I'd like to do (and don't know how), is get an action link from within the controller. I am building up a breadcrumb and want the link to an action. So I don't want to immediately jump to the action (as with RedirectToAction), but just get what the link would be.

View 3 Replies

C# - Retrieve URL For Action From Controller?

Dec 20, 2010

I am calling a Controller Action from a view, within that controller I need to invoke another Action which I will invoke to save the view to a network location as either HTML or Image.

How do I retrieve the URL to an Action from within a Controller. I need the actual URL, this means RedirectionToAction or View() wont work.

Why? I need to pass in a URL which will contain a call to a View. This view will be used to generate an image or HTML document using the System.Windows.Forms.WebBrowser.

.NET 3.5; C#; MVC 1;

I could do something like this, but its dirty ... well it leaves me with that dirty feeling.

using(Html.BeginForm("Action", "MyWorkflowController",
new {
MyId = "bla",
URLToGenerateImage = Url.Action("GenerateImage", "MyWorkflowController")
}))

View 2 Replies

MVC :: Same Processing For Each Action Of A Controller?

Nov 2, 2010

I would like all actions of a controller to read some master page level values from the querystring and write those values to ViewState. How do I do this in ASP.NET MVC?

View 1 Replies

MVC :: Get Current Controller And Action?

Mar 10, 2010

I have a user control in a modal popup for login form. It's ajax post so when login is successfull it doesn't update the rest of the page. Would like to just redirect the user to thier current page but not 100% on how to do this from the accountController.

View 4 Replies

MVC :: Use JQuery To Get Controller Action?

Oct 19, 2010

I have this action on below

public ActionResult Edit(int id)
{
var mtn0120 = __context.GetMtn0120(id);

[code]...

View 4 Replies

MVC :: TDD Of A Controller.Action With An ActionFilterAttribute?

Jan 22, 2010

A well-known benefit of MVC is its suitablility for Test Driven Development (TDD) because you can directly call your controller actions from your test methods.

How can you test the combination of a controller action with a ActionFilter attribute (using OnActionExecuted to modify the ActionResult returned by the Action)? If I just call the Action, it returns the ActionResult from the action, but the filter attribute is never invoked. I think maybe you can get it by Controller.ActionInvoker.InvokeAction(controllerContext, "ActionName"), but you have to accurately mock so much of the controllerContext to make it work that it's a real pain.

View 2 Replies

Can Map Control Event To Controller Action

May 12, 2010

I am creating my first MVC application.I have a View named "Product".I want to use two asp.net control MENU and MULTIVIEW and on OnMenuItemClick event of MENU I want to select the View of MULTIVIEW. Please tell me how can I process asp.net control event in a MVC application.Can we mapp control event to Controller Action.

View 1 Replies

MVC :: Wrong Action Invoked In Controller

Apr 8, 2010

Im fairly new to Asp.Net MVC. I spent some time to fix this but I get it to work. What I have is a:

QuestionController : Controller
{
public ActionResult Add()
{
//do stuff
}
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Add(int roomuid)
{
//do stuff
}
}

now in my view i have : <a href = "/Question/Add">click here </a> The strange thing is that public ActionResult Add(int roomuid) is called and not Add() without get parameters. Even if I change the [AcceptVerbs(HttpVerbs.Get)] to [AcceptVerbs(HttpVerbs.Post)]

View 1 Replies

MVC :: Getting The Area Name Before Controller Action Is Invoked

Mar 7, 2011

I'm writting an application where I want to execute some code before a controller is invoked, even before the controller is created. I would like to somehow hook into the request processing as early as possible after the request is parsed and the RouteData is available. I've tried to hook in by handling the BeginRequest event but at this point there is no RouteData. Is there another place I can look for the area when BeginRequest delivered or is there another place in the request processing pipe that I can hook in to find the area before my controller is invoked.

View 2 Replies

Mvc Expected Controller And Action Not Getting Invoked

Aug 9, 2010

I have a weird issue. I loaded a page using "LoadMyPageController" and there is an ajax_submit_button1 which can be used submit the page. Also there is another ajax_submit_button2 to print the page. This button submits the view model of the page as a whole to the "PrintController" which has a "PrintData" action.
Now when I hit the "ajax_submit_button2", my PrintController.PrintData is not invoked. Instead when I check my fiddler tool the request is made as [URL] which is an invalid URL. I have contructed my ajax_submit_button2 in such a way that it should invoke [URL] But I don't know why LoadMyPage controller is present in my URL. By any chance does asp .net MVC decides that it will take a default controller on its own if it can't find the controller action for any reason. The code is a kind of tightly coupled so can't post it. I want to know if anyone experienced a problem like this.

View 1 Replies

MVC :: Pass A String Value To A Controller Action?

Feb 16, 2011

I am trying to get this functionality on my jokes website:

www.mysite.com/category/bar

To get all the bar jokes ..etc

The way I have my route right now is:

{controller}/{action}/{id}

which means I have to type:

www.mysite.com/category/index/bar

the problem is that even with that, the string parameter "bar" isn't being acknowledged ! ( I know from debugging). Here is my Index action in the Category controller:

[Code]....

View 8 Replies

How To Pass JSON To Controller Action

Mar 6, 2011

I have some textboxes and a table of data created client side that I want pass to a controller as JSON.

I want to use Jquery to enumerate the table.

Assume I have 2 textboxes called name and age. Assume a table with 2 columns. one column with class called phonetype and one column class called phonenumber.

So how do construct the JSON from this?

View 1 Replies

C# - How To Get The Id From / Controller / Action / Id From Within A View Page

Sep 22, 2010

From inside a viewpage, how can I reference the id from the url /controller/action/id without getting this data from the model?

View 3 Replies

MVC :: Data From Action In Controller To View

Jan 19, 2011

So I have a dropdown in a form which when at item is selected postback to database and get some values which I am now storing in an object. I need to get the values from this object into textboxes on the form in the view..how can I do this???

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved