I’m deploying a MCV 1.0 project on a web server running IIS6. (not by my choice) I’ve thru Steve Sandersons article Here and Phil Haack’s article but I’m still having probelms.
Right now I’m trying to implement Option 2 from Steve Sandersons article. The main problem I’m having is with the Home link not rendering correctly. For Instance, in my Site map I have the follwoing:
<%= Html.ActionLink("Home", "Index", "Home") %>
this renders on the pages as http://servername/JCIMS_Orange/Home.mvc which is NOT correct.
HOWEVER THIS LINK:
<%= Html.ActionLink("About", "About", "Home") %>
renders as… http://servername/JCIMS_Orange/Home.mvc/About which is correct
My Global.asax RegisterRoutes function looks like:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute(
"Default2", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
Can anyone tell me why my Home link will not render correctly? I have repeated this error Both on my localhost running on WinXP and on my web server running Win2003 Server.
Appreciate any suggestions or pointers
Why is
http://servername/JCIMS_Orange/Home.mvcnot correct? What were you expecting it to be?Edit: The parameter defaults in your route definition are telling the system that Index is not needed in the route. You could try simply setting the action parameter default to an empty string. That should force the generated urls via
Html.ActionLinkto include the action name even for the Index action.However, I don’t think that’s the best solution. If your images and css aren’t working without the action name, then it sounds like you’re not referencing the path correctly. Could you provide an example of one of your image links and maybe your css file link? Without seeing what they look like, I can suggest that they should start with “/”.
You’ll want to fix those links so that when you’re using a route url that contains an id parameter they will work for that instance also. (e.g.
http://servername/JCIMS_Orange/Products.mvc/Details/5)Edit 2: Because your site is contained in a subfolder, you need to include that subfolder in your image and css paths. Starting a relative URL with “/” means it’s right after the server name. Using “../” means it’s relative to the current path, which as you’ve seen doesn’t work with the default MVC routing because for different actions your url has different numbers of elements.
Including your subfolder path should work perfectly in every situation. Like this: