1

I have the basic controller code :

public async Task<IActionResult> Index(StudentViewModel model,bool isOpen = true)
{
    if (isOpen == false)
    {
        model.Open = false;
    }
    else
    {
        model.Open = true;
    }
    return View(model);
}

View :

<form id="frmStudent" method="post" asp-action="Index">
    <input asp-for="Open " type='checkbox' />
</form>

Script :

$('#Open').change(function () {
    var isOpen = true;
    if (this.checked) {
       isOpen = true;
    }
    else
   {
       isOpen = false;
   }
if(isOpen == true)
{
    //Call the Index method with isOpen = true and reload the page
}
else{
    // Call the Index method with isOpen = false and reload the page.
    }
}

So how do I go about reloading the entire page based on the condition in my script section? Is AJAX the only solution?

TheFallenOne
  • 1,598
  • 2
  • 23
  • 57
  • 1
    with js u can use the location.href to reload or to go on another page, but when u whant to change a particular content u can create a partial views and load them dynamicaly whith js/jquery depending on your needs – spzvtbg Jan 28 '21 at 15:37
  • 1
    Is this helpful? https://stackoverflow.com/a/45582269/3825777 You may also want to include a query string url parameter like this https://stackoverflow.com/a/59858092/3825777 – react_or_angluar Jan 28 '21 at 15:40

2 Answers2

1

You can use this document.location.reload(true);

Achon
  • 90
  • 4
1

try this, 'location.reload();'

$('#Open').change(function () {
    var isOpen = this.checked ? true : false;
    
    if(isOpen){
        //Call the Index method with isOpen = true and reload the page
    }else{
        // Call the Index method with isOpen = false and reload the page. 
    }

    location.reload();
}
Miqayel Srapionyan
  • 587
  • 2
  • 5
  • 15