4

I have an area in my project named Fa in my fa area i have a controller named home and inside my controller i have an action named index .

I published my website but when i type my url i couldn't see my website ,because it should be redirected to mywebsite.com/en/home/index .How can i set this url in my MVC Project

I tried this one but it doens't work.

var route = routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    ).DataTokens = new RouteValueDictionary(new { area = "fa" });
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180
  • What makes you think it would be `mywebsite.com/en/home/index` from the route you have given it should be `mywebsite.com/fa/home/index` – Ashley Medway Feb 21 '15 at 09:21
  • You can see my website :www.exportvision.org ,but when you enter it it doens't work ,but with this url it works www.exportvision.org/en/home/index – Ehsan Akbar Feb 21 '15 at 09:23
  • possible duplicate of [Having issue with multiple controllers of the same name in my project](http://stackoverflow.com/questions/5092589/having-issue-with-multiple-controllers-of-the-same-name-in-my-project) – Ashley Medway Feb 21 '15 at 09:27

2 Answers2

2

you should use this code:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
                routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new {area="fa", controller = "Home", action = "Index", id = UrlParameter.Optional },namespaces: new string[] { "UI.Areas.fa.Controllers"}
            ).DataTokens.Add("area", "fa");
Mehrdad
  • 174
  • 1
  • 4
  • 14
1

You need to specify the namespace for your default route. As you have multiple HomeControllers it needs to know which one to render.

Based on your comments you need to also amend your defaults.

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { area = "en", controller = "Home", action = "Index", id = UrlParameter.Optional },
    namespaces: new string[] { "UI.Areas.en.Controllers" }
);
Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
  • 1
    Note according to your error message. `This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.` – Ashley Medway Feb 21 '15 at 09:33
  • Yes you are right i changed my code and i run it in the local machine let me upload it because the error is changed – Ehsan Akbar Feb 21 '15 at 09:36
  • I upload the bin folder ,please check the URL :www.exportvision.org ,the error is : The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Home/Index.aspx ~/Views/Home/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx ~/Views/Home/Index.cshtml ~/Views/Home/Index.vbhtml ~/Views/Shared/Index.cshtml ~/Views/Shared/Index.vbhtml – Ehsan Akbar Feb 21 '15 at 09:39
  • @EA This is a separate error. There is no view in the default folder structure. Your view should be located at `~/Views/Home/Index.cshtml` – Ashley Medway Feb 21 '15 at 10:15
  • I don't have any views in this folder ,i have an area in my project i t should be area/en/view/home/index – Ehsan Akbar Feb 21 '15 at 10:20
  • @EA add your area in your default, I have edited the answer above to show – Ashley Medway Feb 21 '15 at 11:09