<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ASP.NET MVC</title><link>http://forums.asp.net/1146.aspx</link><description>Discussions regarding Model-View-Controller (MVC) support in ASP.NET.  &lt;a href="http://forums.asp.net/1215.aspx"&gt;T4MVC subforum&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Display list in view</title><link>http://forums.asp.net/thread/3275727.aspx</link><pubDate>Mon, 06 Jul 2009 01:05:43 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3275727</guid><dc:creator>shapper</dc:creator><author>shapper</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3275727.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3275727</wfw:commentRss><description>&lt;p&gt;Hi Gerry,&lt;/p&gt;&lt;p&gt;I got a little bit lost about your approach using four helpers ... However I came up with the following:&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;    // Gallery
    public static String Gallery(this HtmlHelper helper, IList&amp;lt;Product&amp;gt; products, Int32 columns, String name, IDictionary&amp;lt;String, Object&amp;gt; attributes) {

      // Define table
      TagBuilder table = new TagBuilder(&amp;quot;table&amp;quot;);
      if (!String.IsNullOrEmpty(name)) table.Attributes.Add(&amp;quot;id&amp;quot;, name);
      table.MergeAttributes&amp;lt;String, Object&amp;gt;(attributes);     

      // Define rows
      Int32 rows = (Int32)Math.Ceiling(products.Count() / (Double)(columns == 0 ? 1 : columns));

      // Define body
      StringBuilder body = new StringBuilder(&amp;quot;&amp;lt;tbody&amp;quot;);

      // Create table
      for (Int32 i = 0; i &amp;lt; rows; i++) {
        StringBuilder row = new StringBuilder(&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;);
        for (Int32 j = 0; j &amp;lt; columns; j++) {
          StringBuilder column = new StringBuilder(&amp;quot;&amp;lt;td&amp;gt;&amp;quot;);
          Int32 index = i * columns + j;
          if (index &amp;gt;= products.Count) {
            column.Append(&amp;quot;&amp;nbsp;&amp;quot;);
          } else {
            Product p = products[index];
            column.Append(p.Name);
          }
          column.Append(&amp;quot;&amp;lt;/td&amp;gt;&amp;quot;);
          row.Append(column);
        }
        row.Append(&amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;);
        body.Append(row);
      }

      // Return table
      table.InnerHtml = body.ToString();
      return table.ToString();

    } // Gallery&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;It seems to be working. I didn&amp;#39;t find any problem in it.&lt;/p&gt;&lt;p&gt;But any suggestion to improve my code or approach is welcome.&lt;/p&gt;&lt;p&gt;Thanks,&lt;/p&gt;&lt;p&gt;Miguel&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Display list in view</title><link>http://forums.asp.net/thread/3274856.aspx</link><pubDate>Sat, 04 Jul 2009 17:38:32 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274856</guid><dc:creator>gerrylowry</dc:creator><author>gerrylowry</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274856.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274856</wfw:commentRss><description>&lt;p&gt;I described this earlier in this thread.&amp;nbsp; It may not be elegant, but it works.&amp;nbsp; Think about four helpers.&lt;/p&gt;
&lt;p&gt;Helper A:&amp;nbsp; 4 products (table columns) per row.&lt;/p&gt;
&lt;p&gt;If your number of products is evenly divisable by 4, you only need to think about using Helper A:&lt;/p&gt;
&lt;p&gt;Helpers B, C, and D:&amp;nbsp; still 4 columns BUT for the unused column(s), you have only &lt;strong&gt;&amp;amp;nbsp;&lt;/strong&gt; as that column&amp;#39;s content.&lt;/p&gt;
&lt;p&gt;First loop:&amp;nbsp; uses Helper A if 4 or more columns.&lt;/p&gt;
&lt;p&gt;Next piece of code completes the 3, 2, or single remaining column(s).&lt;/p&gt;
&lt;p&gt;In your &lt;strong&gt;Controller&lt;/strong&gt;, you could do something like &lt;strong&gt;ViewData[&amp;quot;extraProducts&amp;quot;] = &amp;quot;2&amp;quot;&lt;/strong&gt;; and the test &lt;strong&gt;extraProducts&lt;/strong&gt; in your &lt;strong&gt;View&lt;/strong&gt; in order to select the correct Helper B, C, or D for the extra 3, 2, or 1 product(s).&lt;/p&gt;
&lt;p&gt;You could pass the upper limit for the loop in the same way.&lt;/p&gt;
&lt;p&gt;As I said, not elegant, but should work.&amp;nbsp; TIMTOWTDI =. there is more than one way to do it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards.&lt;br /&gt;Gerry (Lowry)&lt;/p&gt;</description></item><item><title>Re: Display list in view</title><link>http://forums.asp.net/thread/3274768.aspx</link><pubDate>Sat, 04 Jul 2009 15:19:33 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274768</guid><dc:creator>shapper</dc:creator><author>shapper</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274768.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274768</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;Basically I am trying to create an image gallery where each image has a description and a link under it.&lt;/p&gt;&lt;p&gt;Each image, with its description and link, is a product in my Model.Products.&lt;/p&gt;&lt;p&gt;I tried to include each product into a list item of an orderede list and using pure CSS to style it.&lt;/p&gt;&lt;p&gt;The problem is that the floats and margins don&amp;#39;t allow to obtain what I need ... It&amp;#39;s not easy on cross browser.&lt;/p&gt;&lt;p&gt;So I am thinking in creating a helper that creates a table on the fly.&lt;/p&gt;&lt;p&gt;So I would return 24 products to my view.&lt;/p&gt;&lt;p&gt;Then on my helper I would make rows = Model.Procucts.Count() / 4 and I would get 6 rows.&lt;/p&gt;&lt;p&gt;Then with a loop I would generate each row with its columns for each product.&lt;/p&gt;&lt;p&gt;On a multiple of 4 I will increase the row number and create a new row.&lt;/p&gt;&lt;p&gt;I have paging so the last page might have only, for example, 23 records.&lt;/p&gt;&lt;p&gt;So on my html helper I would have rows = Round Up (Model.Procucts.Count() / 4)&lt;/p&gt;&lt;p&gt;And then I would have a last column empty ...&lt;/p&gt;&lt;p&gt;This would not be a problem with list but with tables I can&amp;#39;t have a row with less columns than another ...&lt;/p&gt;&lt;p&gt;... well I can but in this case would get a wider column which is not the objective.&lt;/p&gt;&lt;p&gt;What do you think?&lt;/p&gt;&lt;p&gt;I am just starting to create the helper.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Display list in view</title><link>http://forums.asp.net/thread/3274758.aspx</link><pubDate>Sat, 04 Jul 2009 15:03:33 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274758</guid><dc:creator>gerrylowry</dc:creator><author>gerrylowry</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274758.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274758</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;shapper:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; 
&lt;p&gt;Your solution is what I have been trying but I have been having a few problems.&lt;/p&gt;
&lt;p&gt;&lt;span style="BACKGROUND-COLOR:#ffff00;"&gt;&lt;strong&gt;I think you need to clear the productlist to ...&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;???????????????????&lt;/p&gt;
&lt;p&gt;Hello shapper ....&amp;nbsp;please finish your thought ...... please give more detailed information because I am uncertain as to your exact question.&lt;/p&gt;
&lt;p&gt;There are a number of deeper considerations, for example, at four products per line, will all of your products fit on a web page that is not horrendously long ... if this is not&amp;nbsp;the case, you will also want to display your products in so many per page, for example, 25 lines x 4 = 100 products per page.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Gerry (Lowry)&lt;/p&gt;</description></item><item><title>Re: Display list in view</title><link>http://forums.asp.net/thread/3274721.aspx</link><pubDate>Sat, 04 Jul 2009 14:11:01 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274721</guid><dc:creator>shapper</dc:creator><author>shapper</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274721.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274721</wfw:commentRss><description>&lt;p&gt;Your solution is what I have been trying but I have been having a few problems.&lt;/p&gt;&lt;p&gt;I think you need to clear the productlist to ...&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Display list in view</title><link>http://forums.asp.net/thread/3274638.aspx</link><pubDate>Sat, 04 Jul 2009 12:34:20 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274638</guid><dc:creator>gerrylowry</dc:creator><author>gerrylowry</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274638.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274638</wfw:commentRss><description>&lt;p&gt;@ &lt;a href="http://forums.asp.net/members/Tijn.aspx"&gt;Tijn&lt;/a&gt;&amp;nbsp;~~ you seem to be saying in a different way more or less what I described.&lt;/p&gt;
&lt;p&gt;Note, however, that your solution works perfectly only when the number of products is evenly divisible by four.&lt;/p&gt;
&lt;p&gt;With a row of four, the first &lt;strong&gt;&lt;span style="COLOR:#3366ff;"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;&lt;/strong&gt; gets product &lt;strong&gt;&lt;em&gt;n&lt;/em&gt;&lt;/strong&gt;, the&amp;nbsp;second &lt;strong&gt;&lt;span style="COLOR:#3366ff;"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;&lt;/strong&gt; gets product &lt;strong&gt;&lt;em&gt;n+1&lt;/em&gt;&lt;/strong&gt;, the third &lt;strong&gt;&lt;span style="COLOR:#3366ff;"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;&lt;/strong&gt; gets product &lt;strong&gt;&lt;em&gt;n+2&lt;/em&gt;&lt;/strong&gt;, and the fourth &lt;strong&gt;&lt;span style="COLOR:#3366ff;"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;&lt;/strong&gt; gets product &lt;strong&gt;&lt;em&gt;n+3&lt;/em&gt;&lt;/strong&gt;.&amp;nbsp; A 4 product helper would simplify the HTML.&amp;nbsp; It is likely possible to write a html helper that handles a variable number of products; that would be better than having separate helpers for 4 products, 3 products, 2 products, and 1 product.&lt;/p&gt;
&lt;p&gt;Also, I&amp;#39;m not a css expert ... is there a reason you did not use a css &lt;strong&gt;&lt;span style="COLOR:#ff0000;"&gt;class&lt;/span&gt;&lt;/strong&gt; &amp;quot;productlist&amp;quot;&amp;nbsp;instead of your &lt;strong&gt;&lt;span style="COLOR:#ff0000;"&gt;id&lt;/span&gt;&lt;/strong&gt; &amp;quot;productlist&amp;quot;?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Gerry (Lowry)&lt;/p&gt;</description></item><item><title>Re: Display list in view</title><link>http://forums.asp.net/thread/3274487.aspx</link><pubDate>Sat, 04 Jul 2009 08:54:29 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274487</guid><dc:creator>Tijn</dc:creator><author>Tijn</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274487.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274487</wfw:commentRss><description>&lt;p&gt;The cleanest solution is to just output a single list (ul, li) and tweak the css so that the products will displayed next to each other and automatically go to a new row when there is no room for the next item.&lt;/p&gt;&lt;p&gt;html:&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="xhtml"&gt;&amp;lt;ul id=&amp;quot;productlist&amp;quot;&amp;gt;
    &amp;lt;li&amp;gt;product 1&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;product 2&amp;lt;/li&amp;gt;
    ...
    &amp;lt;li&amp;gt;product 8&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; css:&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="css"&gt;#productlist
{
    list-style-type: none;
    margin: 0;
    padding: 0;
    width: 800px;
}

#productlist li
{
    float: left;
    width: 200px;
    height: 200px;
    margin: 0;
    padding: 0;
}&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Display list in view</title><link>http://forums.asp.net/thread/3274120.aspx</link><pubDate>Sat, 04 Jul 2009 00:35:05 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274120</guid><dc:creator>gerrylowry</dc:creator><author>gerrylowry</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274120.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274120</wfw:commentRss><description>&lt;p&gt;shapper, you could give more information.&amp;nbsp; My guess you may be using a field set and the standard .css that comes with the default ASP.NET MVC template.&amp;nbsp; You may have to tweak the .css to not force a new paragraph.&lt;/p&gt;
&lt;p&gt;You can determine how many products you have to display.&lt;/p&gt;
&lt;p&gt;You can write four HTML&amp;nbsp;helpers:&amp;nbsp; 4 product helper; 3 product helper; 2 product helper; 1 product helper&lt;/p&gt;
&lt;p&gt;Then from&amp;nbsp;modulus 4 on product count, if&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0:&amp;nbsp; loop using the 4 product helper only.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1:&amp;nbsp; loop using the 4 product helper, use the 1 product helper for the last product&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2:&amp;nbsp; loop using the 4 product helper, use the 2 product helper for the last 2 products&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3:&amp;nbsp; loop using the 4 product helper, use the 3 product helper for the last 3 products&lt;/p&gt;
&lt;p&gt;The above idea works although it is not elegant.&lt;/p&gt;
&lt;p&gt;TIMTOWTDI =. there is more than one way to do it&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regars,&lt;br /&gt;Gerry (Lowry)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Display list in view</title><link>http://forums.asp.net/thread/3274100.aspx</link><pubDate>Sat, 04 Jul 2009 00:07:28 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274100</guid><dc:creator>shapper</dc:creator><author>shapper</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274100.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274100</wfw:commentRss><description>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;On a view I am displaying a list of products using a loop for and a table.&lt;/p&gt;&lt;p&gt;The problem is that I don&amp;#39;t want to display one product per row, I want to display 4 products per row each in its column.&lt;/p&gt;&lt;p&gt;So it&amp;#39;s like:&lt;/p&gt;&lt;p&gt;Row 1 &amp;gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;gt; Column 1 to 4 (Products 1 to 4)&lt;/p&gt;&lt;p&gt;Row 2 &amp;gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;gt; Column 1 to 4 (Products 5 to 8)&lt;/p&gt;&lt;p&gt;How can I do this?&lt;/p&gt;&lt;p&gt;Thanks,&lt;/p&gt;&lt;p&gt;Miguel&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>