سؤال

Hello I have the contents of my select list stored in a ViewModel and I would like to display the select list on a IEnumerable page.

The error I'm receiving is "CS1061: 'System.Collections.Generic.IEnumerable' does not contain a definition for 'QualifiedList' and no extension method 'QualifiedList' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

Any idea how to reference the select list in an IEnumerable View?

View

@model IEnumerable<MEOregistration.Models.MEOmodel>
    @Html.DropDownListFor(model => Model.Status, Model.QualifiedList)

ViewModel

namespace MEOregistration.Models
{
    public class MEOmodel
    {
        public IEnumerable<SelectListItem> QualifiedList
        {
            get
            {
                return new[]
                {
                    new SelectListItem { Value = "Pending Qualficiation", Text = "Pending Qualification" },
                    new SelectListItem { Value = "Dis-Qualified", Text = "Dis-Qualified" },
                    new SelectListItem { Value = "Qualified", Text = "Qualified" }
                };
            }
        }
    }
}
هل كانت مفيدة؟

المحلول

You cannot reference the the member that way. You need to change your model type to @model MEOregistration.Models.MEOmodel

Or use a partial meo.cshtml:

@model MEOregistration.Models.MEOmodel
@Html.DropDownListFor(model => Model.Status, Model.QualifiedList)

Called by

@foreach(var meo in Model)
{
  @Html.Partial("partial",meo)
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top