1. I don't think we need ToList here at all. Also, I would put this complex expression into a variable (especially since it's used a few times).
Finally, why does he put it in the view code instead of the controller's code? Isn't it too complex for the view (putting too much code in the view is not a good practice).
>Hi,
>
>another developer who I'v e helped in the past has asked me to help him work out why he is not getting the expected data with the following code:
>
>
@foreach (var claims in Model.Claims.ToList().Where(w => w.memberid == User.Identity.Name.Substring(User.Identity.Name.IndexOf('(') + 1, (User.Identity.Name.IndexOf(')') - 1) - User.Identity.Name.IndexOf('('))) )
> {
> var uid = User.Identity.Name.Substring(User.Identity.Name.IndexOf('(') + 1, (User.Identity.Name.IndexOf(')') - 1) - User.Identity.Name.IndexOf('('));
> var mid = claims.memberid;
> if (uid == mid)
> {
> <tr class="odd-row">
> <td>N/A</td>
> <td>@claims.healthplanid</td>
> <td>@claims.claimnumber</td>
>
>
>Unfortunately I do not have a clue (having never used LINQ, which is what I think this code is using) but I've asked him how come the first line (with the ToList().Where) doesn't just pull out the correct set of records and he doesn't know.
>
>The User.Identity.Name should contain a string like this: Frank Cazabon (214-00-0121)
>
>But apparently it is pulling out lots of other data but not the expected set.
>
>Can any one explain why?
If it's not broken, fix it until it is.
My Blog