C# 根据复选框选择重新加载页面

C# 根据复选框选择重新加载页面,c#,jquery,asp.net-core,C#,Jquery,Asp.net Core,我有基本的控制器代码: public async Task<IActionResult> Index(StudentViewModel model,bool isOpen = true) { if (isOpen == false) { model.Open = false; } else { model.Open = true; } return View(model); } 那么,如何根据脚

我有基本的控制器代码:

public async Task<IActionResult> Index(StudentViewModel model,bool isOpen = true)
{
    if (isOpen == false)
    {
        model.Open = false;
    }
    else
    {
        model.Open = true;
    }
    return View(model);
}
那么,如何根据脚本部分的条件重新加载整个页面呢?AJAX是唯一的解决方案吗?

您可以使用它 文档。位置。重新加载(true)

试试这个,“location.reload();”


有了js,你可以使用location.href重新加载或转到另一个页面,但当你想更改某个特定内容时,你可以创建一个部分视图,并根据需要使用js/jquery动态加载它们。这有帮助吗?您可能还希望包含一个查询字符串url参数,如下所示
<form id="frmStudent" method="post" asp-action="Index">
    <input asp-for="Open " type='checkbox' />
</form>
$('#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.
    }
}
$('#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();
}