Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a *.cshtml page in JavaScript [closed]

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?

like image 467
Fakhar uz zaman Avatar asked Mar 16 '13 07:03

Fakhar uz zaman


People also ask

How can I make the browser wait to display the page until it's fully loaded?

Just add this to the script above: $(document). ready(function() { setTimeout('$("#container"). css("opacity", 1)', 1000); });

How do you show page loading Div until the page has finished loading?

Step 1: Add a background with a spinner gif on top of the page, then remove them when everything is loaded. Step 2: Add a little script right after the opening body tag to start displaying the load/splash screen.

What is Cshtml?

What is a CSHTML file? A file with . cshtml extension is a C# HTML file that is used at server side by Razor Markup engine to render the webpage files to user's browser.


1 Answers

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>
like image 121
Dave Alperovich Avatar answered Sep 18 '22 08:09

Dave Alperovich