Before drafting this question I went through some links of this type, and Implemented the same type of code block but unable to find out what mistake am I doing.
Problem.
I have view model which contains 2 list data and one is of the list which I want to display it into dropdownlist control.
Viewmodel
public class ClaimVM
{
public List<ClaimHistoryModel> claimHistoryModel { get; set; }
public List<CategoryModelDum> categoryModel { get; set; }
}
CategoryModelDum.cs
public class CategoryModelDum
{
public string CategoryName { get; set; }
public Int16 ID { get; set;
}
currently I am receiving data for both the lists and I am passing this viewmodel from controller to VIew(since one of the list is working as expected).
here is my dropdownlist code
@Html.DropDownListFor(m => m.categoryModel.Select(x => x.CategoryName), new SelectList(Model.categoryModel, "ID", "CategoryName"), "Select Category", new { @class = "ddlList" })
so I need categorymodel data to be displayed on dropdownlist. but this is throwing exception saying:-
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions
I am pretty sure that I am doing some silly mistake, but any help will be appreciated.
UPDATE - 1
here is the code snipped which works as expected. but not with view model class.
@model.ClaimHistory.Models.CategoryModelDum
@Html.DropDownListFor(model => model.CategoryName, new SelectList(ViewBag.CategoryType, "ID", "CategoryName", Model.ID), new { @class = "ddlList" })