What is the difference between returning a View, a PartialView and JSON from an action?

ASP.NET MVC Controllers & Actions Basic Fresher1–2 Yrs Conceptual 1 min read

Quick Answer

View() renders a full page (content + layout). PartialView() renders just the view markup with no layout — for injecting a fragment into an existing page via AJAX. Json() serialises an object to JSON — for API-style calls or client-side rendering.

View() gives back a whole page — it runs through _ViewStart and gets wrapped in the layout. PartialView() returns only that view's markup with no layout, which is what I return from an action that an AJAX request calls to swap out a section of the page — a results list, a modal body. Json() just serialises an object, for when the browser is doing the rendering. In an actual Web API I'd return Ok(obj) and let content negotiation produce the JSON.

  • A full View runs _ViewStart and wraps the content in the layout.
  • A PartialView skips the layout — return it from an action that an AJAX call hits to refresh a section (a search results list, a modal body).
  • Json is for when the client does the rendering (a JS framework) or for a lightweight endpoint. In Core Web API you'd usually use Ok(obj) and content negotiation instead.
  • A common pattern: one action returns a full View on a normal request and a PartialView when Request.Headers["X-Requested-With"] indicates AJAX.