<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - ASP.NET MVC MultiSelect issue</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - ASP.NET MVC MultiSelect issue</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Mon, 20 May 2013 07:09:47 GMT</pubDate>
	<lastBuildDate>Mon, 20 May 2013 07:09:47 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>6</c9:totalResults>
	<c9:pageCount>-6</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - ASP.NET MVC MultiSelect issue</title>
		<description><![CDATA[<p>I'm trying to create a listbox with multiple selected&nbsp;items but it doesn't work.</p>
<p>&nbsp;</p>
<p>My model:</p>
<p><a rel="lightbox" href="http://home.scarlet.be/~zippyv/images/mvc/model.png"><img src="http://home.scarlet.be/~zippyv/images/mvc/model.png" alt="Model with many to many relationship"></a></p>
<p>&nbsp;</p>
<p></p>
<pre class="brush: vb">
Function Edit(ByVal id As Integer) As ActionResult
 Dim vm As New ViewModels.NewsItemViewModel() With {
  .NewsItem = _
db.NewsItems.Include(&quot;NewsCategories&quot;).Single(Function(item) item.Id = id),
  .Categories = _
New MultiSelectList(db.Categories, &quot;Id&quot;, &quot;Category&quot;, .NewsItem.NewsCategories)
 }
 Return View(vm)
End Function
</pre>
<p></p>
<p>The first param of MultiSelectList is the list of Categories, the last param is the list of selected categories.</p>
<p>&nbsp;</p>
<p>It doesn't work because nothing gets selected</p>
<p></p>
<pre class="brush: html">
&lt;select id=&quot;NewsItem_NewsCategories&quot; 
multiple=&quot;multiple&quot; name=&quot;NewsItem.NewsCategories&quot;&gt;
&lt;option value=&quot;1&quot;&gt;Politics&lt;/option&gt;
&lt;option value=&quot;2&quot;&gt;Economy&lt;/option&gt;
&lt;option value=&quot;3&quot;&gt;Sports&lt;/option&gt;
&lt;/select&gt;
</pre>
<p></p>
<p>&nbsp;</p>
<p>Then I read somewhere that the last param expects a list of strings with the ids. So I modified my code</p>
<p></p>
<pre class="brush: vb">
Function Edit(ByVal id As Integer) As ActionResult
 Dim vm As New ViewModels.NewsItemViewModel() With {
  .NewsItem = _
db.NewsItems.Include(&quot;NewsCategories&quot;).Single(Function(item) item.Id = id),
  .Categories = _
New MultiSelectList(db.Categories, &quot;Id&quot;, &quot;Category&quot;, .NewsItem.NewsCategories.Select(Function(c) c.id.ToString())
 }
 Return View(vm)
End Function
</pre>
<p></p>
<p>&nbsp;</p>
<p>When I looked up the values during runtime I got some hope:</p>
<p><a rel="lightbox" href="http://home.scarlet.be/~zippyv/images/mvc/code.png"><img src="http://home.scarlet.be/~zippyv/images/mvc/code.png" alt=""></a></p>
<p>&nbsp;</p>
<p>But the resulting HTML is the same as what I showed in my first html sample: nothing is selected.</p>
<p>&nbsp;</p>
<p>Since the MVC code is open source you can view MultiSelectList's code: <a href="http://home.scarlet.be/~zippyv/downloads/MultiSelectList.cs">
download here</a>.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/560601#560601</link>
		<pubDate>Sun, 11 Jul 2010 16:07:11 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/560601#560601</guid>
		<dc:creator>ZippyV</dc:creator>
		<slash:comments>6</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ZippyV/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - ASP.NET MVC MultiSelect issue</title>
		<description><![CDATA[<p>The code in the View:</p>
<p></p>
<pre class="brush: html">&lt;%: Html.ListBoxFor(Function(m) m.NewsItem.NewsCategories, Model.Categories)%&gt;</pre>
<p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/6aa67acc316c42e1a23f9dea00aa977c#6aa67acc316c42e1a23f9dea00aa977c</link>
		<pubDate>Sun, 11 Jul 2010 16:25:20 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/6aa67acc316c42e1a23f9dea00aa977c#6aa67acc316c42e1a23f9dea00aa977c</guid>
		<dc:creator>ZippyV</dc:creator>
		<slash:comments>6</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ZippyV/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - ASP.NET MVC MultiSelect issue</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">ZippyV said:</div><div class="quoteText">
<p>The code in the View:</p>
<p></p>
<pre class="brush: html">&lt;%: Html.ListBoxFor(Function(m) m.NewsItem.NewsCategories, Model.Categories)%&gt;</pre>
<p></p>
</div></blockquote>
<p>I have had my share of headache's with the HTML.ListBoxFor</p>
<p>&nbsp;</p>
<p>One of the gotacha's is; don't put any ViewData[] or other stuff on your form that interferes with the name, ID's ect.</p>
<p>&nbsp;</p>
<p>Here's how I use em, that I found works:</p>
<p>&nbsp;</p>
<p>The SalesOpsManagers is just an IList&lt;string&gt;</p>
<p>&nbsp;</p>
<p><font size="2"></p>
<p>&lt;%</p>
</font><font size="2" color="#0000ff"><font size="2" color="#0000ff">=</font></font><font size="2"> Html.ListBoxFor(model =&gt; model.SalesOpsManagers, (</font><font size="2" color="#2b91af"><font size="2" color="#2b91af">IEnumerable</font></font><font size="2">&lt;</font><font size="2" color="#2b91af"><font size="2" color="#2b91af">SelectListItem</font></font><font size="2">&gt;)ViewData[</font><font size="2" color="#a31515"><font size="2" color="#a31515">&quot;TerritorySalesOpsManagers&quot;</font></font><font size="2">],
</font><font size="2" color="#0000ff"><font size="2" color="#0000ff">new</font></font><font size="2"> { style =
</font><font size="2" color="#a31515"><font size="2" color="#a31515">&quot;width:250px;&quot;</font></font><font size="2"> })%&gt;</font>
<p></p>
<p>&nbsp;</p>
<p>And the viewdata is in the form of a selectlistitem, doesnt need to be multiselectlist item</p>
<p>&nbsp;</p>
<p>hope this helps you</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/29dd05cd558d4583948c9dea00aa978a#29dd05cd558d4583948c9dea00aa978a</link>
		<pubDate>Mon, 12 Jul 2010 07:19:25 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/29dd05cd558d4583948c9dea00aa978a#29dd05cd558d4583948c9dea00aa978a</guid>
		<dc:creator>Maddus Mattus</dc:creator>
		<slash:comments>6</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Maddus Mattus/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - ASP.NET MVC MultiSelect issue</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Maddus Mattus said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">ZippyV said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>I have had my share of headache's with the HTML.ListBoxFor</p>
<p>&nbsp;</p>
<p>One of the gotacha's is; don't put any ViewData[] or other stuff on your form that interferes with the name, ID's ect.</p>
<p>&nbsp;</p>
<p>Here's how I use em, that I found works:</p>
<p>&nbsp;</p>
<p>The SalesOpsManagers is just an IList&lt;string&gt;</p>
<p>&nbsp;</p>
<p><font size="2"></p>
<p>&lt;%</p>
</font><font size="2" color="#0000ff"><font size="2" color="#0000ff">=</font></font><font size="2"> Html.ListBoxFor(model =&gt; model.SalesOpsManagers, (</font><font size="2" color="#2b91af"><font size="2" color="#2b91af">IEnumerable</font></font><font size="2">&lt;</font><font size="2" color="#2b91af"><font size="2" color="#2b91af">SelectListItem</font></font><font size="2">&gt;)ViewData[</font><font size="2" color="#a31515"><font size="2" color="#a31515">&quot;TerritorySalesOpsManagers&quot;</font></font><font size="2">],
</font><font size="2" color="#0000ff"><font size="2" color="#0000ff">new</font></font><font size="2"> { style =
</font><font size="2" color="#a31515"><font size="2" color="#a31515">&quot;width:250px;&quot;</font></font><font size="2"> })%&gt;</font>
<p></p>
<p>&nbsp;</p>
<p>And the viewdata is in the form of a selectlistitem, doesnt need to be multiselectlist item</p>
<p>&nbsp;</p>
<p>hope this helps you</p>
</div></blockquote>
<p>As you can see from my controller action, I don't put anything in the viewdata.</p>
<p>&nbsp;</p>
<p>I've seen people creating a list of SelectListItem using LINQ but they are all in C# and I have no idea how to translate it to VB.NET.</p>
<p>&nbsp;</p>
<p>Example:</p>
<p></p>
<pre class="brush: text">
var friendNames = 
 (from tweet in friendTweets
 select new SelectListItem
 {
  Text = tweet.ScreenName,
  Value = tweet.ScreenName
// Selected = True|False should also be filled in here
 })
 .ToList();
</pre>
<p></p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/f052d441a1f441aea9d69dea00aa979c#f052d441a1f441aea9d69dea00aa979c</link>
		<pubDate>Tue, 13 Jul 2010 09:02:23 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/f052d441a1f441aea9d69dea00aa979c#f052d441a1f441aea9d69dea00aa979c</guid>
		<dc:creator>ZippyV</dc:creator>
		<slash:comments>6</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ZippyV/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - ASP.NET MVC MultiSelect issue</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">ZippyV said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Maddus Mattus said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>As you can see from my controller action, I don't put anything in the viewdata.</p>
<p>&nbsp;</p>
<p>I've seen people creating a list of SelectListItem using LINQ but they are all in C# and I have no idea how to translate it to VB.NET.</p>
<p>&nbsp;</p>
<p>Example:</p>
<p></p>
<pre class="brush: text">
var friendNames = 
 (from tweet in friendTweets
 select new SelectListItem
 {
  Text = tweet.ScreenName,
  Value = tweet.ScreenName
// Selected = True|False should also be filled in here
 })
 .ToList();
</pre>
<p></p>
</div></blockquote>
<p></p>
<pre class="brush: vb">Dim friendNames = (From tweet In friendTweets _
                   Select New SelectListItem() With _
                   { _
                       .Text = tweet.ScreenName, _
                       .Value = tweet.ScreenName _
                   }).ToList()</pre>
<p></p>
<p>&nbsp;</p>
<p>This really ain't rocket science. <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-4.gif' alt='Tongue Out' /></p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/7a3f74c60de5441c9ebe9dea00aa97a7#7a3f74c60de5441c9ebe9dea00aa97a7</link>
		<pubDate>Tue, 13 Jul 2010 12:12:19 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/7a3f74c60de5441c9ebe9dea00aa97a7#7a3f74c60de5441c9ebe9dea00aa97a7</guid>
		<dc:creator>Sven Groot</dc:creator>
		<slash:comments>6</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Sven Groot/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - ASP.NET MVC MultiSelect issue</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">ZippyV said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Maddus Mattus said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>As you can see from my controller action, I don't put anything in the viewdata.</p>
<p>&nbsp;</p>
<p>I've seen people creating a list of SelectListItem using LINQ but they are all in C# and I have no idea how to translate it to VB.NET.</p>
<p>&nbsp;</p>
<p>Example:</p>
<p></p>
<pre class="brush: text">
var friendNames = 
 (from tweet in friendTweets
 select new SelectListItem
 {
  Text = tweet.ScreenName,
  Value = tweet.ScreenName
// Selected = True|False should also be filled in here
 })
 .ToList();
</pre>
<p></p>
</div></blockquote>
<p>Zippy,</p>
<p>&nbsp;</p>
<p>does the problem exist?</p>
<p>&nbsp;</p>
<p>if so, can you post your asmx or aspx?</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/2c04df8280f242d5a0a19dea00aa97b4#2c04df8280f242d5a0a19dea00aa97b4</link>
		<pubDate>Tue, 13 Jul 2010 12:29:39 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/560601-ASPNET-MVC-MultiSelect-issue/2c04df8280f242d5a0a19dea00aa97b4#2c04df8280f242d5a0a19dea00aa97b4</guid>
		<dc:creator>Maddus Mattus</dc:creator>
		<slash:comments>6</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Maddus Mattus/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>