Hi @ANB ,
The MatchCollection.ICollection<Match>.Contains(Match) method determines whether the collection contains a specific value.
bool ICollection<Match>.Contains (System.Text.RegularExpressions.Match item);
You can check https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.matchcollection.system-collections-generic-icollection-system-text-regularexpressions-match--contains?view=net-6.0
Maybe you can change the method, you can refer to this demo:
controller:
public ActionResult Index()
{
List<FileModel> matchesFiles = new List<FileModel>()
{
new FileModel { file="banner.jpg", width="100" },
new FileModel { file="footer.jpg", width="100" },
new FileModel { file="leftSide.jpg", width="50" },
new FileModel { file="footer.jpg", width="100" },
};
List<FileModel> fileArray = new List<FileModel>();
foreach (FileModel item in matchesFiles)
{
if (!fileArray.Any(f => f.file == item.file))
{
fileArray.Add(item);
}
}
ViewBag.fileArray = fileArray;
return View();
}
model:
public class FileModel
{
public string file { get;set;}
public string width { get; set; }
}
.cshtml:
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h3>fileArray</h3>
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<th>Id</th>
<th>Name</th>
</tr>
@foreach (var fileArray in ViewBag.fileArray)
{
<tr>
<td>@fileArray.file</td>
<td>@fileArray.width</td>
</tr>
}
</table>
</body>
</html>
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.