I think that to fix the code you will need to do the following:
@{
var myId = Model.myId;
List<MyObject> newObj = Model.MyList.Where(l => l.Id == myId).ToList();
}
Which just removes @ in front of the model.
However, I believe that the best solution to your problem is to try to save the logic code in your controller, and not your opinion.
As an example, if you use Partial View.
In your view, you can trigger an action and pass your model as follows:
@Html.Action("MyAction", Model)
This will trigger a controller action that will make your choice ie
[ChildActionOnly]
public ActionResult MyAction(MyModel model)
{
var newList = model.MyList.Where(l => l.Id == myId).ToList();
return PartialView("_MyPartial", newList);
}
Then use the attribute @modelin partial ie
@model List<MyObject>
source
share