Search code examples
c#asp.netrazor-pages

how to call c# function in razor page with out redirect page


this goal page

as in the link above I want to see the sub-object of the tree on the web, so if I press the ▶ button, I want to search the DB through efcore.

To solve this, I thought about how to execute a specific function in cshtml, but I realized that the problem is that even if the function is executed, there is no change in the view. Whenever the ▶ button to view sub-items in the tree is clicked, I want to search for sub-items in the DB and update the view without page redirection.

I tried using the redirect method. it is not comfortable

cshtml

@if (Model.authority)
    {content }

cshtml.cs

public IActionResult OnPostChagneMainCategorySelect()
{
     return RedirectToPage("/MyPage/Leader", new
     {
         _selectionWorkState= workState,
         _selectionItem = searchingItems,
         _selectionMain = searchingCategorys,
     });
}


Solution

  • If you want to return the same page you are on you can use

    return Page();