skip to Main Content

I have an application with the overall directory structure with main directories as ‘Check-in / Arrivals / Departures for the entire application. Models directory, controllers, and views all go according to this directory hierarchy. I need the application to startup at the departure section on the WIP page.

When I try to launch, I get this error:

Server Error in ‘/’ Application.
The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /

I have the router.config file setup with the following route:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Departures/MasterWip", action = "Index", id = UrlParameter.Optional }
        );  

In the Controllers/Departures/MasterWipController.cs file, I have the following code:

public ActionResult Index()
{
    IRepositoryFactory repoFactory = new RepositoryFactory();

    IMasterWipRepository wipRepo = repoFactory.GetMasterWipRepo();
    model = wipRepo.GetAllByNLIDate(new DateTime(2022, 1, 14));

    ViewBag.Model = model;

    return View("~/Views/Departures/MasterWip");
}

What am I missing or is incorrect?

2

Answers


  1. Chosen as BEST ANSWER

    The ActionResult method must return the View("../Departures/MasterWip"); in which case is it looking for directory guidance during its parsing. The other option is to use the following:

    return View("~/Views/Departures/MasterWip.cshtml"); 
    

    where it is looking for a specific file.

    This is in addition to Ahmed_Amr's comment about change to the router.config file.


  2. in mapRoute just add the controller name

    routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "MasterWip", action = "Index", id = UrlParameter.Optional }
                );  
    

    and check with debugger if it hit the index view if it does just return view()

    public ActionResult Index()
            {
                IRepositoryFactory repoFactory = new RepositoryFactory();
                IMasterWipRepository wipRepo = repoFactory.GetMasterWipRepo();
                model = wipRepo.GetAllByNLIDate(new DateTime(2022, 1, 14));
                ViewBag.Model = model;
                return View();
            }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search