On a View I am calling Render action with from within a loop, the action will create an array of objects and return to a PartialView with a Grid to display the results.
View:
foreach (var item in Model)
<%Html.RenderAction("GridData", "Customer", new {passidx = (new Random().Next(50))});%>
Controller:
public ActionResult GridData(int passidx)
{
List<Customer> cList = new List<Customer>{new Customer() { name = "c" + (1 + passidx).ToString(), address = "a" + (1 + passidx).ToString() },
new Customer() { name = "c" + (2 + passidx).ToString(), address = "a" + (2 + passidx).ToString() }};
return View(cList);
}
Roughly 2 out of every 3 times I refresh the page the values for each element in the grids are the same even though I am passing a random number to each Action which is appended to the displayed text.
instead of calling
new Random()inforeach, declare one instance beforeforeach. you are getting duplicate because it is using same seed.See this great answer.
Example: