ASP.NET MVC reading an element's custom html attribute when submitting
-
09-10-2019 - |
Question
I'm new to ASP.NET and MVC in particular. Now, I'm trying to understand if I can easily get values of custom attributes of submitted data.
For example, When writing something like this inside a form (which works and posts and I can get the checkbox value) <%= Html.CheckBox("cb1", new { listen = "listen:6" }) %>
Can I get the value of "listen" directly or do I need JS? (I know I can just use hidden fields, but I'm I'm asking anyway)
Thanks
Solution
You cannot; when a form is POST-ed, only the name/value pairs are sent. This is a general feature of HTML and forms, and not specific to ASP.NET or MVC.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow