Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

asp.net mvc - partial view was not found or no view engine supports the searched locations

I have following controller code:

public MyController:Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [ChildActionOnly]
    public ActionResult MyPartialViewAction()
    {
        return PartialView("~/Views/Shared/MyCustomFolder/_MyPartialView",PartialViewModel);
    }
}

and my Index view has the following code :

@HTML.Action("MyPartialViewAction")

When I run the Web app I get HttpException with InnerExceptionMessage as :

InnerException {"The partial view '~/Views/Shared/MyCustomFolder/_MyPartialView' was not found or no view engine supports the searched locations. The following locations were searched: ~~/Views/Shared/MyCustomFolder/_MyPartialView"} System.Exception {System.InvalidOperationException}

What I have tried till now :

  • Tried moving _MyPartialView from ~/Views/Shared/MyCustomFolder to ~/Views/Shared/ and ~/Views/MyControllerFolder but still error exists

  • Tried changing my Index View code to @HTML.RenderAction() but no luck.

Any inputs on where I'm going wrong ?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just in case the selected answer is not working for you:

I changed the build action of the cshtml file to Content and it fixed it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...