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?
Just add this to the script above: $(document). ready(function() { setTimeout('$("#container"). css("opacity", 1)', 1000); });
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 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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With