Home » Jquery » javascript – Dynamically change partial razor view on runtime when window screen is resized

javascript – Dynamically change partial razor view on runtime when window screen is resized

Posted by: admin February 22, 2020 Leave a comment

Questions:

I want to change partial view on run time when screen width is changed and want to remove styles of old partial view and add new styles

<div id="LargeScreen">
   @Html.Partial("/Views/Shared/_PartialNavbar1.cshtml")
</div>
<div id="MidiumScreen">
   @Html.Partial("/Views/Shared/_PartialNavbar2.cshtml")
</div>
$(document).ready(function () {
   AdjustNavbar();
}

$(window).resize(function () {
   AdjustNavbar();
});

function AdjustNavbar() {
  var width = $(window).width();

  if (width >= 1320) {
    // how can I render a partial view path for LargeScreen
  } else if (width > 768 && width < 1320) {
    // how render partial view path for MidiumScreen
  }
}
How to&Answer: