MVC PartialView not found

11,771

Solution 1

Since it seems you are calling from a different structured controller, try to specify the path:

  @{Html.RenderPartial("~/Views/MDT/Jobs/CompletedJobParts.cshtml", Model);}

Solution 2

What is 'MDT' and why are you using it as a subdirectory of the Views folder? From my understanding - when trying to render the partial, it is trying to find it in a folder under the 'Views' folder that is named after the type of the Model (~/Views/Jobs/), or if it can't find it, in your shared views (~/Views/Shared/). Have you tried removing the extra directory level?

Share:
11,771
Jason
Author by

Jason

Updated on June 15, 2022

Comments

  • Jason
    Jason almost 2 years

    I am trying to render a partial view within my main view. however, I am getting the error:

    The partial view 'CompletedJobParts' was not found or no view engine supports the searched locations. ~/Views/Jobs/CompletedJobParts.aspx ~/Views/Jobs/CompletedJobParts.ascx ~/Views/Shared/CompletedJobParts.aspx ~/Views/Shared/CompletedJobParts.ascx ~/Views/Jobs/CompletedJobParts.cshtml ~/Views/Jobs/CompletedJobParts.vbhtml ~/Views/Shared/CompletedJobParts.cshtml ~/Views/Shared/CompletedJobParts.vbhtml

    (sorry about formatting)...

    the physical layout (location) of my view is Views/MDT/Jobs/CompletedJobParts.cshtml and I'm trying to call it from a view in the same location (ie Views/MDT/Jobs/Index.cshtml). I thought it may be a routing issue so I entered:

       routes.MapRoute(
            "MDT",
            "MDT/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
    

    into my Global.asax.cs file, but it doesn't seem to search there either (ie, there's no MDT section coming up in the locations it's searching for).

    I'm using this to render within index.cshtml:

        <div id="parts_div">
          @{Html.RenderPartial("CompletedJobParts", Model);}
        </div>
    

    What do I need to do to get my View to find my PartialView?

    TIA