After redirect the page, the radio button which i selected earlier should be maintain, How i do it?
Html.RadioButtonFor(model => model.flag, "R", htmlAttributes: new { @id = "oflag1" })
Refusal
Html.RadioButtonFor(model => model.flag, "RJ", htmlAttributes: new { @id = "oflag2" })
Return to JTP
Html.RadioButtonFor(model => model.flag, "RA", htmlAttributes: new { @id = "oflag4" })
Call for Addln.Particulars
Html.RadioButtonFor(model => model.flag, "FC", htmlAttributes: new { @id = "oflag3" })
Forward to Chairman
Html.ValidationMessageFor(model => model.flag, "", new { @class = "text-danger" })
Naimish MakwanaPosted Jan 10, 2024, 9:47 AM
To maintain the state of a selected radio button after a page redirect, you can use
localStorageorsessionStoragein JavaScript. Here’s a simple example of how you can do it:This script will save the value of the selected radio button in the user’s browser when a radio button is clicked. Then, when the page is loaded, it will check if there is a saved radio button value and select that radio button.
Please replace
'flag'with the actual name attribute of your radio buttons. Also, make sure to include jQuery in your project for this script to work12.Remember,
localStoragepersists across sessions and will work even if the user closes and reopens their browser, whilesessionStorageis limited to the current session and will be cleared when the user closes their browser. Choose the one that best fits your needs.Please note that this method will not work if the user has disabled web storage in their browser settings. In such cases, you might need to consider server-side solutions.
Sachin SinghPosted Jan 10, 2024, 9:38 AM
Yes you can do that with JS only also, but that won't be a good approach, here is an example
Note:- You can increase the expiration time from 7 days to any number of days
Garima BansalPosted Jan 10, 2024, 9:32 AM
Can this solution can be resolve by js?
Sachin SinghPosted Jan 10, 2024, 8:05 AM
To maintain the value you have to do something like this