Get values of hidden fields in controller (ASP.NET MVC)

10,516

Hidden fields are just like any other form fields when you get to the POST action being sent to the server. There's nothing that makes them special outside of their display (or lack thereof, rather) in the browser. Thus, they should be accessible in much the same way you currently access other form fields.

How do you currently access other form fields? If they're just mapped to a model which is being passed into the controller action, then hidden fields should be mappable just the same.

Conversely, you should be able to manually access any HTTP POST data from HttpContext and the Request object.

Share:
10,516
Rasto
Author by

Rasto

Entrepreneur, UX consultant, full-stack developer with strongest competency in Swift & iOS. Can get die-hard about top-notch UX and code quality. Diving deeper into React and getting excited about GraphQL. My pro history chapters are written in C#, Objective-C, Java, JS, TS, Flow, even Haskel, Prolog & Pascal. Sports and outdoor enthusiast. Love exploring cultures around the world. Found in mountains in the winter and at seaside during summer. Amater photographer. Always happy to learn and share what I learned e.g. externally giving lectures at my alma mater.

Updated on July 18, 2022

Comments

  • Rasto
    Rasto almost 2 years

    Can I reach the value of hidden fields in controller action ? And how ? Do I put it in the model somehow ?

    Thank you


    EDIT: some code example how to store something in hidden field and retrieve it on postback would be appreciated.