asp.net-mvc-routing

ASP.Net MVC - HTTP Status Codes (i.e. 303, 401, 404, etc)

In ASP.Net MVC is it possible to use either Redirect or RecirectToAction to call for example a 303 error? I am working my way through a book titled "ASP.NET MVC 1.0 Website Programming" and the source is making calls such as return this.Redirect(303, FormsAuthentication.DefaultUrl); but this call only functions with an external library,...

Recommended url structure for parent child list in mvc

If I am listing child items of a parent in an asp.net mvc app, is there a best practice to how the url structure should be formed? Example: 1. http://app/parent/<parentID>/children 2. http://app/parent/children/<parentID> I'm personally more inclined to choose option 1, but am wondering if there is a particular way that...

asp mvc: specifying a view name does not change the url

I have an create action in my controller for the HttpPost. inside that action I insert the record in the db, and then return a view specifying a different action name, because I want to take the user somewhere else, such as to the details view of the record they just created, and I pass in the current model so I don't have to re-load th...

ASP.NET MVC Default URL View

I'm trying to set the Default URL of my MVC application to a view within an area of my application. The area is called "Common", the controller "Home" and the view "Index". I've tried setting the defaultUrl in the forms section of web.config to "~/Common/Home/Index" with no success. I've also tried mapping a new route in global.asax, ...

ASP.NET MVC - HTML Extension method building a URL or link

Consider an extension method whose purpose is to either: render an <a> tag on some condition, just return a string without a link   Question: in an extension method, how can you leverage the proper routing logic with Route Values, etc. rather than hardcoding the string. I suspect HtmlHelper.GenerateRouteLink is part of the solution, ...

Is there an equivalent to Ruby on Rails' respond_to format.xml, etc in ASP.Net MVC?

In Ruby on Rails you can write a simple controller action such as: def index @movies = Movies.find(:all) respond_to do |format| format.html #index.html.erb format.xml { render :xml => @movies } format.json { render :json => @movies } end end For those unfamiliar with RoR, def index in this case wo...

ASP.NET MVC Action Parameter Naming

Using the default route provided, I'm forced to name my parameters "id". That's fine for a lot of my Controller Actions, but I want to use some better variable naming in certain places. Is there some sort of attribute I can use so that I can have more meaningful variable names in my action signatures? // Default Route: routes.MapRoute...

Why isn't my Route.Ignore working on this static file in my ASP.NET MVC application?

Background I have a PDF file located (under my Project) in an Assets > Documents folder: When my application gets deployed, it gets deployed to a particular folder on the domain. For example, http://www.domain.com/MyAppFolder. I want to be able to access this PDF file by linking to http://www.domain.com/MyAppFolder/Assets/Documents/E...

Can Areas in an ASP.Net MVC 2 Application map to a subdomain?

Is there a way to map the Areas within an ASP.Net MVC 2 application to subdomains such as: movies.example.com/Theater/View/2 instead of example.com/Movies/Theater/View/2 (where { area = "Movies", controller = "Theater", action = "View", id = 2 } ) ...

jQuery AJAX load not executing on ASP.NET MVC Controller Action

Hey folks, I have a simple thing going here: two divs and two calls to load partials (controller actions with PartialView as results). I am dealing with two controller actions: Index and ItemDetail. The jQuery load works in the view returned by the Index action, but not on ItemDetail. These items are in the same controller and you ca...

Does HtmlHelper.RouteLink know about virtual directories?

I have an issue where I'm generating links for my MVC app in a custom HtmlHelper, and RouteLink isn't aware that the MVC application has a virtual directory. This means I can debug and use the app fine in testing, but it generates invalid links in production. Is there a way to get RouteLink() or ActionLink() to include the virtual direct...

RedirectToAction Return URL Formatting Long-winded/incorrectly

Hi there, Why in ASP.NET MVC is it when I use a: return this.RedirectToAction("Index", "Page", new { pageKey = "test/ho/hum"}) or using the MVCContrib extension: return this.RedirectToAction<PageController>(c => c.Index("test/ho/hum")) formats my return URL as: http://localhost:8882/?pageKey=test%2Fho%2Fhum and not: http://localho...

Redirect from one Area's action to a action in the "root"-area?

I use the latest version of ASP.Net MVC 2 RC. My question is, how do I redirect from one action that's in the "Blog"-area to the index-action in the home-controller that exists in the "root" of my application (no area)? I tried: return RedirectToAction("index", "home"); but this redirects to /Blog/home, where Blog is the name of my ...

What object property contains the Route Name being used when inside ControllerBase

How do I find the Route Name that is being used when inside of the ControllerBase using it? For example, I have a route like this: routes.MapRoute("Search", "{controller}.mvc/{action}/{criterion}", new { controller = "", action = "", criterion = "" }); ...and in my ControllerBase I need the Object.Property that contains "Search" or t...

Action-View binding: magic!

Say there's HomeController with an Details-action. return View() will send data to the Detals.aspx in the Home folder. But who makes that binding? and what if I want it to go to Edit.aspx instead? Background: Alot of the code in Details.aspx and Edit.aspx is identical, save for one textbox. Maybe by MVC rigor, the view is not supposed t...

Asp.Net MVC Identify Site via Url

I have an application that will support multiple sites. The site will be determined based on the url. For example http://myapp/site/abc123/... and http://myapp/site/xyz123/... The site code will drive a lot of the functionality for example themes, available modules, etc... Questions: 1-)I need to validate the site code is valid and...

Refactoring an algorithm

I'm trying to re-implement ASP.NET MVC routing rules in C++ for my own MVC application. Currently the code takes at least O(N) at best case and more if accessing the controller/action inside an unordered_map is not O(1). I would like my code to prefer a route with a controller that's already in the URI, for instance if the current URI is...

MVC Routing for categories with spaces

I have a website that has categories for the products. I wanted to have the categories defined in a route pretty much like www.domain.com/categoryA. Here's my problem what if I have category in my database that is 'Boxing Gloves' how do I handle the space in the category name? ...

MVC Custom Routes and ActionLinks

We are working with an asp.net mvc app that is shared by multiple clients. We need the urls to include the clients url friendly name. For example: domain.com/clientName/controller/action/id This below appears to be working when it comes to routing, but the "clientName" is not generated correctly for the action link helpers. _routes....

Can a route prefix a controller's name? issues with urls and controller name collisions

I want my urls structure to be like this: www.stackoverflow.com/order/... www.stackoverflow.com/admin/order/... Now both of the above are using different controllers. /controllers/ordercontroller /controllers/admin/ordercontroller Is there a way that I can have this url structure? I was thinking if I could do this: /controllers/...