Loading a *.cshtml page in JavaScript

asp.net-mvc, jquery, jquery-events, razor

Solution

If you use a Partial with Child Action

example

[ChildActionOnly]
ActionResult _Partial()
{

  return PartialView();
}

then the easiest way to do this would be to designate a div (`divPartial`) in your layout

<div id="divPartial"></div>

Within your View, href event, and use the JQuery load method.

<a href="#" id="aLink">click me</a>

<script>
$(document).ready(function() {
  $('#aLink').click(function() {
      $('#divPartial').load('@Url.ActionLink("_Partial","Controller")');
  });
});

</script>

Problem

I have to load a `*.cshtml` partial page in my layout page after a link is clicked. How it can be done in JavaScript/jQuery or Razor/MVC?

Original source