简体   繁体   中英

Setting default value when linking back to previously visited page?

In my current MVC project, I need to be able to set the default value of a <input type="range"... /> to the value that it already has been assigned as, using a Session variable.

<input name="answer" type="range" id="slider" defaultValue="@Session["Question5Answer"]" min="10" max="200" />

This works if I click the back button in the browser, but not if I click a different button on another page that links back to this page.

I know that the session variable is saved, because there is a submit button on the same page as this <input type="range"... /> which links to another page, which does display the Session variable's value. And yet whenever I click a link on that page which sends be straight back to the page with the <input type="range"... /> on it, the defaultValue is not set to the value of the Session variable, and yet when I use the browser's back button, it does save and the defaultValue is set to the value of the Session vairable.

What am I doing wrong? How can I fix this? If there is any more snippets of code that would be required for answering this question, just let me know. Thanks in advance!

defaultValue is a DOM Property , html markup equivalent for defaultValue is value property.

see here :

value : https://www.w3.org/wiki/HTML/Elements/input/text

defaultValue : https://developer.mozilla.org/en/docs/Web/API/HTMLInputElement

Hope that helps..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM