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

Similar Messages:

RenderAction Not Finding Action Method In Current Controller In Current Area?

Mar 15, 2010

I'm creating an ASP.NET MVC 2 (RTM) project that uses areas. The Index action of the Home controller of one area needs to use RenderAction to generate a sub-section of the page. The action called is also defined in the same Home controller. So the call should just be:

<% Html.RenderAction("List") %>

However, I get an exception:A public action method 'List' was not found on controller 'RareBridge.Web.Areas.Events.Controllers.HomeController'.

Note that I'm not in the "Events" area! I'm in a completely different area. If I remove the "Events" home controller, then the exception still occurs but names a different controller (still not the one I want it to call).

I've also tried providing the controller name and area to the RenderAction method, but the same exception occurs. What is going on here?

BTW: I am using Autofac as my IoC container

View 2 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

Determine The Current Controller Action In An Mvc Sitemap?

Jul 13, 2010

I'm stuck with a problem of which I can not imagine I am the first person having to deal with it. Yet, Google comes up with nothing useful and neither does SO, so here I am. I'm using ASP.NET MVC1 with a sitemap. Using an html helper I create a navigation menu that highlights the current selected option in the Site.Master page. Common scenario and easily done by using:

foreach ( SiteMapNode subnode in node.ChildNodes) {
if (SiteMap.CurrentNode == subnode) { //got ourselves the current here }

That's all fine and dandy, however, my problem is that I have 1 controller with multiple actions. Consider the following scenario:

* clients
* suppliers
* maintainance

They would all be in my AccountController, doing a search that is identical but with a different AccountTypeId value. When I read the SiteMap.CurrentNode value it gives me merely the info that I am using the AccountController, but not which action I called. I've tried a whole bunch of things but I can not get the action that was requested. I hope I gave enough info there to give you an idea of the scenario. If you need anything else, let me know.

View 2 Replies

MVC :: Out Of The Box MVC2 Controller / Delete Controller Is Refusing To Return Any Class Information

Nov 6, 2010

my MVC2 delete and only my delete controller is refusing to return any class information. Its really similar to my edit function and the views are all auto-generated so I don't see the problem.

Function Delete(ByVal id As Integer) As ActionResult

View 4 Replies

Get The Physical Controller Class File Path Of The Executing Action Method?

Dec 21, 2010

Assume the current executing action method is Index() in Home controller. From within Index(), how to obtain the physical file path of the Home controller? Assume we don't know the file structure until runtime.

View 2 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


But RedirectToAction returns RediretToRouteResult

View 7 Replies

C# - Using Grasp Controller With MVC Controller - How To Make An Object Always Visible For A Controller

Dec 28, 2010

UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, that follows the UP(Unified Process). It uses a Grasp Controller pattern to interact with domain classes by some methods like NewSale(), AddNewItemToSale() and CloseSale. In windows form, I can instantiate a object of this class in the UI and then use its methods to perform the actions. This works well in Client apps, but when I use mvc, I cannot find a way to instantiate an object (one for each user) that was always visible for a Controller (MVC). I cannot insert as an attribute inside Controller because it always create a new one.

View 1 Replies

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:


And here is the controller 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

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:


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? 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)
"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


How can I use routing to redirect this url to


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


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 :: 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

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);


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 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 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
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

Copyrights 2005-15, All rights reserved