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??

6
  • stackoverflow.com/questions/5248183/… - take a look here. and here: msdn.microsoft.com/en-us/library/dd492503(v=vs.118).aspx Commented Feb 26, 2015 at 18:40
  • @Ahmedilyas...I already looked there and it doesn't address this - it's no help. Commented Feb 26, 2015 at 18:42
  • Unable to replicate do you have any special setting. More details may help . Commented Feb 26, 2015 at 19:43
  • You are have _CoverageSearch.cshtml in your path, but Index.cshtml in the error - is exactly what you are getting? Commented Feb 26, 2015 at 19:47
  • @Carl...Index.cshtml is where @Html.Partial("~/Areas/Search/Views/Shared/_CoverageSearch.cshtml") is/lives. Commented Feb 26, 2015 at 20:07

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.