I have a hidden field in my HTML view
<%:Html.HiddenFor(model=>model.ContactId) %>
I want to put this value in viewBag so that I can use it in controller. How to do that? Also, how will I access this in controller?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t have the notion of
postbackin ASP.NET MVC and theViewBagis available to you to deliver data to the view, but not to transfer data back and forth between the view and the controller.If your hidden input is in a form then upon posting the form the new value would be accessible via
model.ContactId.Example: