Products and Tags. How to create this?

Last post 06-06-2008 2:52 PM by panjkov. 1 replies.

Sort Posts:

  • Products and Tags. How to create this?

    06-05-2008, 7:46 PM
    • Contributor
      3,569 point Contributor
    • shapper
    • Member since 11-28-2004, 9:15 PM
    • Posts 2,947

    Hello,

    I am creating a products controller following the example on MVC videos.

    The List method is as follows:

        public ActionResult List(int? page) {      
           dt.Products = (from p in db.Products
                                orderby p.UnitPrice
                                select p).ToPagedList(page ?? 0);
           return View("List", viewData.ToList); 
        }
    In my case the products are classified using tags. Each product can have 0 to many tags, so Products table as a Many to Many relationship:
      Products > ProductsTags > Tags  

    In my list I need to display all the tags associated to each post, separated by commas.

    The same happens with the edit and update form.

    My model is created by LinqToSQL.

    I don't know exactly how to do this ... should I create a new type that encapsulates each product with its info and respective tags?

    Anyway, any help would be great. 

    I was also looking at repositories but I am not sure if this helps me in this situation or if it is only a way to separate the model from the code in the controller.

    Thank You,

    Miguel 

  • Re: Products and Tags. How to create this?

    06-06-2008, 2:52 PM
    • Member
      525 point Member
    • panjkov
    • Member since 01-12-2003, 12:16 AM
    • Sarajevo/Banjaluka, Bosnia and Herzegovina
    • Posts 167

    Perhaps you might use ViewData Dot notation, as explained in Matt Hawley blog post http://blog.eworldui.net/post/2008/05/ViewData-quot3bdotquot3b-Notation-Expressions-in-ASPNET-MVC.aspx

    In that case you might create another class as wrapper around Product and its tags, as you already mentioned.

    Dragan Panjkov
    [http://blogpanjkov.qsh.eu/] [http://www.microsoft.com/bih]

    Filed under: ,
Page 1 of 1 (2 items)