Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
168 views
in Technique[技术] by (71.8m points)

c# - Reload page based on Checkbox selection

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?

question from:https://stackoverflow.com/questions/65940212/reload-page-based-on-checkbox-selection

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...