0

I'm seeing "does not contain a definition for..." error.

Here is the code in View

      @model Variant.SystemV.Web.Models._TaggingVM

      @Html.ListBoxFor(x=>x.Tags, Model.SelectedTags, new { @class = "chzn-select", data_placeholder = "Select Tag(s)...", style = "width: 500px" })

Here's my Model

public class _TaggingVM
{
    public IEnumerable<Tag> SelectedTags { get; set; }
    public IEnumerable<Tag> Tags { get; set; }
    public Article Article { get; set; }
}
0

1 Answer 1

3

It's because Html.ListBoxFor() extension takes a parameter type of IEnumerable<SelectListItem> and probably the property in your viewmodel doesn't implement it.

You can create the items in your view like this:

@Html.ListBoxFor(x => x.SelectedTags, new SelectList(Model.Tags, "Id", "Text"))

It assumes you have properties named Id and Text in your Tag class. Also you should probably use the SelectedTags property in your expression. It will make sure you collect them back when the form is posted.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.