0

Why does this work and render the partial view properly?

@Html.Partial("~/Areas/Search/Views/Shared/_CoverageSearch.cshtml")

While this returns an error:

@{
    Html.RenderPartial("~/Areas/Search/Views/Shared/_CoverageSearch.cshtml");
}

You tried to visit '/Areas/Search/Views/Home/Index.cshtml' which cannot be found.

Why is it complaining about the View it's rendered on??

Big Daddy
  • 5,160
  • 5
  • 46
  • 76
  • http://stackoverflow.com/questions/5248183/html-partial-vs-html-renderpartial-html-action-vs-html-renderaction - take a look here. and here: https://msdn.microsoft.com/en-us/library/dd492503(v=vs.118).aspx – Ahmed ilyas Feb 26 '15 at 18:40
  • @Ahmedilyas...I already looked there and it doesn't address this - it's no help. – Big Daddy Feb 26 '15 at 18:42
  • Unable to replicate do you have any special setting. More details may help . – Dnyanesh Feb 26 '15 at 19:43
  • You are have _CoverageSearch.cshtml in your path, but Index.cshtml in the error - is exactly what you are getting? – Carl Feb 26 '15 at 19:47
  • @Carl...Index.cshtml is where @Html.Partial("~/Areas/Search/Views/Shared/_CoverageSearch.cshtml") is/lives. – Big Daddy Feb 26 '15 at 20:07
  • @Dnyanesh...There may be something set somewhere that's preventing this from working, but I don't know. Routing?? – Big Daddy Feb 26 '15 at 20:08

1 Answers1

1

Functionally, they're the same, assuming you actually have something like:

@{ Html.RenderPartial("~/Areas/Search/Views/Shared/_CoverageSearch.cshtml"); }

Instead of just:

Html.RenderPartial("~/Areas/Search/Views/Shared/_CoverageSearch.cshtml");

The latter is not valid Razor syntax, so the view wouldn't render properly.

Otherwise, the only difference is that RenderPartial writes directly to the response, whereas Partial returns a string. But, neither method would cause the error you indicate.

I think most likely, you have debugged while having this view as your active tab. Visual Studio will sometimes get confused and make the actual view file your start URL, which is inaccessible via a browser. Just change the URL in the browser to the actual route that ends up loading that view.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • I added the razor tags that I omitted. I ran the app with Partial (good), replaced it with RenderPartial (Bad). I know they're functionally the same - I just don't get the error. – Big Daddy Feb 26 '15 at 18:50