Lee Atkinson
Lee Atkinson

Reputation: 2181

ASP.NET MVC @Url.Action includes current route data

Suppose I:

Why would it include the current id even when I didn't specify it, and is there any way of preventing this (apart from 'hard-coding' the URL directly)?

Upvotes: 1

Views: 2450

Answers (2)

Oskar Austegard
Oskar Austegard

Reputation: 4639

I believe this is a regression bug in MVC3, as discussed by Phil Haack here: http://haacked.com/archive/2011/02/20/routing-regression-with-two-consecutive-optional-url-parameters.aspx

This is the correct answer: https://stackoverflow.com/a/7133304/27938

Upvotes: 0

Seth
Seth

Reputation: 8373

You did specify the value for id when you put /foo/bar/test in the browser address bar. You are essentially calling the method Bar with the parameter "test" in your foo controller. Your simple view is irrelevant when you browse directly.

To answer your last question you may need to have a re-look at the way you are using MVC.

Upvotes: 1

Related Questions