Hellooo everyone!
I'm still new to MVC, so I'm trying to figure out the different options that I can't currently find that were originally in WinForms.
All I need to do is append text into a ViewBag, rather than just overwriting the previous value.
Scenario:
- Web Request calls API to retrieve data which is a JSON Object that stores a JSON Array.
- Code (Listed Below) loops through and puts text into ViewBag.
- Webpage loads, but has put the very last array value into ViewBag (Which I fully understand is because I'm overwriting the previous value in the ViewBag).
All I want to do is to add the additional Array values into the ViewBag, so that if the array has 1,2,3,4 objects, the ViewBag will display 1,2,3,4 rather than just 4.
In WinForms I would do something simple like
Textbox1.Text +=alertName.toString();
or in a .NET App I would just simply use
textBox1.AppendText("Some text");
Is there a similar way to do this in MVC?
What I have tried:
var jsonClient = new WebClient();
jsonClient.Credentials = new NetworkCredential("XXXX", "XXXX");
jsonClient.Headers.Set("Content-Type", "application/json");
jsonClient.Headers.Set("Accept", "application/json");
var alertsSettings = jsonClient.DownloadString("http://XXXX:XXXX/api/alerts/settings");
JObject results = JObject.Parse(alertsSettings);
foreach (var result in results["data"])
{
string alertName = (string)result["alertName"];
ViewBag.alertNameData = alertName.ToString();
}