To explain, my initial setup was as follows:
Contollers:
Library => Controllers => ParametersController.cs
Library => Controllers => ReaderLevelController.cs
Library => Controllers => ResourceTypeController.cs
Views:
Library => Views => Parameters => Index.cshtml
Library => Views => ReaderLevel => Index.cshtml
Library => Views => ResourceType => Index.cshtml
Each view referenced its appropriate Model like so:
@model IEnumerable<Library.DAL.PrmTbl_Level>
and each controller contained an ActionResult
for Index(), some FormCollections
and not much else. The screens displayed fine, and pulled, edited and updated the db no problem.
I wanted to change my views to a more descriptive hierarchy so moved my View files like so:
Views:
Library => Views => Parameters => Index.cshtml
Library => Views => Parameters => ReaderLevel => Index.cshtml
Library => Views => Parameters => ResourceType => Index.cshtml
I then updated the ParametersController.cs
file to reflect the new ActionResults that would now be directed toward it, it being the 'parent' file:
public ActionResult ResourceType() { return View("ResourceType/Index"); }
Now however the new 'sub' screens (ReaderLevel & ResourceType, in this example) do not display, as an error is thrown when a foreach loop tries to run through their relevant Model - which now returns as null. I am confused as to how changing the location of the View file can alter the viability of the data access (as, to my mind, the Model is filled via the ab path @model IEnumerable<Library.DAL.PrmTbl_Level>
which does not change).
Can someone explain how changing the View's location affects its accessing of its Controller and Model?
EDIT
My current setup (file structure as above):
ParametersController
public ActionResult Index() {
ViewBag.Title = "Parameters";
return View();
}
public ActionResult ResourceType() {
return RedirectToAction("ResourceType");
}
This gives me the appropriate url, but 'Firefox has detected that the server is redirecting the request for this address in a way that will never complete.' Using the RedirectToAction "ResourceType","Index"
resolves to the url '/Index/ResourceType' and the resource cannot be found.