I work on asp.net razor page .i face issue my issue is when navigate to page after make submit it will reset all values on page
I read more articles related to the issue will solved by using hidden fields
so suppose I have asp.net razor page have username and email
and i need store fields of username and email on hidden fields to be available after submit post
so can you provide to me sample to store username and email on hidden fields so prevent value from reset after submit and can navigate to other pages
so Can you please provide to me sample please to hidden fields store username and email?
Amit MohantyPosted Jul 6, 2023, 9:46 AM
Check this
ahmed salahPosted Jul 6, 2023, 7:19 AM
my input type is text so how to save it ohidden fields please
these two fields user name and email on my form is ready for user to input data
so How to save data of input user text on hidden field please
fff
Lokesh VarmanPosted Jul 6, 2023, 2:16 AM
First, you'll need to add the hidden fields within the
tags of your Razor page. These hidden fields should have unique IDs and names, which will be used to identify them. Here's an example of how you can include the hidden fields in your form:In the above code, the
usernameHiddenandemailHiddenfields are hidden inputs that store the values of@Model.Usernameand@Model.Email, respectively.Next, you'll need to handle the form submission in the associated .cshtml.cs file. In the
OnPostmethod, you can retrieve the values from the hidden fields and update the model properties accordingly. Here's an example:In the
OnPostmethod, you access the values of the hidden fields usingRequest.Form["fieldName"]. Then, you assign those values to the corresponding model properties (UsernameandEmailin this case). After that, you can redirect to another page usingRedirectToPage("OtherPage")or perform any other necessary processing.By following these steps, the values of the username and email fields will be stored in the hidden fields, ensuring they are preserved even after the form submission and navigation to other pages.