람다 식 외부에있는 변수에 값을 할당하려고합니다. 예를 들면.람다 식 외부 변수에 값 지정
model.Categories =
productService.GetAllCategories().Select(
c => new CategoryViewModel
{
CategoryId = c.CategoryId,
CategoryName = c.CategoryName,
IsSelected = c.CategoryId == cat
//how can i also assign the CategoryName to model.SelectedCategory?
}).ToList();
model
또한 내가 c.CategoryId == cat
경우에 CategoryName
을 할당 할 SelectedCategory
의 속성이 포함되어 있습니다. 어떻게해야합니까?
이렇게하면 SelectedCategory에 범주 개체가 할당됩니다. 원하는 결과는 CategoryName을 SelectedCategory에 지정하는 것입니다. –
@ 메트로 아! 그 부분을 놓쳤다. 결정된! –