I work or razor page asp.net core 7 . i face issue i can't store vlue of selected value option on local storage
so please How to do that ?
Code
Print Server
--Select--
@foreach (var branches in Model.branches)
{
@branches.vBranchDesc
}
Search
Createon page model what i do
C#
public class ShelfLabelPrinterSetUpModel : PageModel
{
public async Task OnPostSearchAsync(string selectbranchid)
{
// how to store value of local storage here
}
}
Tahir AnsariRank #366 · 6.8K reputationPosted Aug 20, 2023, 1:02 AM EDT
To achieve this, you can use JavaScript in combination with your Razor Pages code.
Add a script section within your Razor Page to handle storing the selected value in the local storage when the form is submitted.
@section Scripts { function toggleButtonVisibility() { // Your existing toggleButtonVisibility function logic // Store selected value in local storage var selectedValue = document.getElementById("branch-select").value; localStorage.setItem("selectedBranch", selectedValue); } }In your Razor Page model, retrieve the stored value from local storage when handling the form submission.
public class ShelfLabelPrinterSetUpModel : PageModel { public async Task OnPostSearchAsync(string selectbranchid) { // Retrieve value from local storage var storedValue = HttpContext.Session.GetString("selectedBranch"); if (!string.IsNullOrEmpty(storedValue)) { // Use the storedValue as needed } // Your existing logic for OnPostSearchAsync } }