Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm fairly new to MVC4, and I'm having a problem getting a custom route off the ground.

I don't want to explain what my end goal is, since it's fairly complicated, but right now I simply want this url:

/Home/GetView/contacts/pv

to hit the GetView action of my home controller, and pass it parameters of "contacts" and "pv" for its module and name parameters

public PartialViewResult GetView(string module, string name)

Unfortunately when I set a breakpoint, both of these parameters are null.

Here's the route I'm trying to use

routes.MapRoute(
    name: "PartialView",
    url: "{controller}/{action}/{module}/{name}"
);

and I've also tried

routes.MapRoute(
    name: "PartialView",
    url: "Home/GetView/{module}/{name}",
    defaults: new { controller = "Home", action = "GetView" }
);

According to the docs I'm reading that should work fine, so I'm not sure what I'm doing wrong.

share|improve this question
    
Are you putting your new route before the default route? –  Jason Berkan Apr 9 '13 at 19:41
    
@Jason - yes I am. –  Adam Rackis Apr 9 '13 at 19:42
    
Odd. I copied your second MapRoute and your GetView method into a fresh MVC4 app and it works fine. –  Jason Berkan Apr 9 '13 at 19:46
    
@Jason - I think this may be a caching issue - the address is coming from a link in my htm file, and I think it's getting cached such that the wrong address is getting sent over the wire :( –  Adam Rackis Apr 9 '13 at 19:48
1  
CTRL+F5 FTW! (15 chars). –  Jason Berkan Apr 9 '13 at 19:49
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.