I got a Viewbag in my controller how can I change text color without using CSS ? I have tried using System.Drawing.Color but color name is assigned to viewbag as a text. Here is my controller
public ActionResult change_color()
{
ViewBag.stackoverflow= "This text has to be red";
ViewBag.stackoverflow.ForeColor = System.Drawing.Color.Red;
return View()
}
No, you cannot use that enum with ViewBag. The reason is that ViewBag is just a placeholder for other objects, so it doesn’t even make sense to assign that variable to that property, as the property
ForeColoryou are trying to access should be on the object you put into ViewBag to hold.In the same sense, why not do
so you assign a color to a number (not text, number)?
You are basically trying to do an assignment to
string.ForeColorwhich does not exist.