Note that there are some explanatory texts on larger screens.

plurals
  1. POHtml.ListBox() and MultiselectList
    primarykey
    data
    text
    <p>I've a little problem with an Html.ListBox.</p> <p>I am developing a personal blog in ASP.NET MVC 1.0 and I created an <code>adminpanel</code> where I can add and edit a post! During this two operations, I can add also tags.</p> <p>I think of use an <code>Html.ListBox()</code> helper to list all tags, and so I can select multiple tags to add in a post! The problem isn't during the add mode, but in the edit mode, where I have to pre-select post's tags.</p> <p>I read that I have to use a <code>MultiSelectList</code> and so in its constructor pass, tags' list and tag's list(pre-selected value).</p> <p>But I don't know how to use this class.</p> <p>I post, some code:</p> <p>This is my models method that get all list tags in selectlist</p> <pre><code>public IEnumerable&lt;SelectListItem&gt; GetTagsListBox() { return from t in db.Tags orderby t.IDTag descending select new SelectListItem { Text = t.TagName, Value = t.IDTag.ToString(), }; } </code></pre> <p>So in Edit (Get and Post), Add(Get and Post) I use a ViewData to pass this list in <code>Html.ListBox()</code>.</p> <pre><code>ViewData["Tags"] = tagdb.GetTagsListBox(); </code></pre> <p>And in my view</p> <pre><code>&lt;%=Html.ListBox("Tags",ViewData["Tags"] as SelectList) %&gt; </code></pre> <p>So with this code it's ok in Add Mode.</p> <p>But in Edit Mode I need to pre-select those values.</p> <p>So Now, of course I have to create a method that get all tagsbypostid.</p> <p>and then in <code>ViewData</code> what Must I to pass?</p> <p>Any suggest?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload