Is there any way to create and use dynamic properties for ViewBag, based on strings?
Something like
ViewBag.CreateProperty("MyProperty");
ViewBag.Property("MyProperty") = "Myvalue";
Thank you
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.
I just found out that ViewData can be used to create such properties for ViewBag
So to create property CityErrorMessage I have to use
and then in the view I can use
EDIT:
I created the ViewBag’s properties dynamically, because I received the name of field with validation error in a list
So the code actually is