What code in inherit part

Posted by FullmetalBoy on Stack Overflow See other posts from Stack Overflow or by FullmetalBoy
Published on 2011-01-12T08:48:23Z Indexed on 2011/01/12 8:54 UTC
Read the original article Hit count: 275

Filed under:
|

Problem:
Having problem to find a source solution (inherit code in view state) to display data from SokningPerformSearchViewModel and its generic list in view state.

Questions/request:
Need to display data from my viewmodel SokningPerformSearchViewModel and its generic list as a strongly typed (if possible)?

This question is a follow-up from my previous question Display a view with many to many relationship

// Fullmetalboy

namespace BokButik1.ViewModels
{
    public class SokningPerformSearchViewModel
    {
        public List<BokSearchResultViewModel> Boksss { get; set; }
    }
}


namespace BokButik1.ViewModels
{
    public class BokSearchResultViewModel
    {
        public List<Bok> Boks { get; set; }

        public List<Bok_Forfattare> Bok_Forfattares { get; set; } 
    }
}

public class SokningController : Controller
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult PerformSearch(string txtSearch, Kategori kategoriNummer)
    {

        Search myTest = new Search(txtSearch, kategoriNummer);
        SkaparListor mySkaparListor = new SkaparListor(myTest.HamtaBokListaFranSokFunktion(), myIBok_ForfattareRepository.HamtaAllaBok_ForfattareNummer());

        var performViewModel = mySkaparListor.RattBokOchForfattarListaTillViewModel();

        var SokningIndexViewModel = new SokningPerformSearchViewModel
        {
            Boksss = performViewModel
        };


        return View(SokningIndexViewModel);   
    }

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
    Inherits="System.Web.Mvc.ViewPage<BokButik1.ViewModels.SokningPerformSearchViewModel>" %>


<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    PerformSearch
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>PerformSearch</h2>


        <table>
    <% foreach (var bok in Model.Boksss) { %> 


    <tr>
        <td><%: bok.Boks %> av</td>
        <td rowspan="2"><%: bok.Bok_Forfattares %></td>
        <td rowspan="2"><div id="Div1"><input type="submit" value="Köp" /></div></td>
    </tr>
    <tr>
        <td></td>
    </tr>
        <tr>
        <td>.. </td>
    </tr>


    <% } %> 
    </table>


</asp:Content>

namespace BokButik1.Models
{
    public class SkaparListor
    {

        private List<Bok_Forfattare> _myIBok_ForfattareRepository;
        private List<Bok> _Bok;
        private List<BokSearchResultViewModel> _ViewBokSearch;

        public SkaparListor(List<Bok> pSpecifikBokLista, List<Bok_Forfattare> pBok_ForfattareLista)
        {
            _Bok = pSpecifikBokLista;
            _myIBok_ForfattareRepository = pBok_ForfattareLista;
            _ViewBokSearch = new List<BokSearchResultViewModel>();
        }


        public List<BokSearchResultViewModel> RattBokOchForfattarListaTillViewModel()
        {
            foreach (var a in _Bok)
            {
                List<Bok> aaBok = new List<Bok>();
                List<Bok_Forfattare> aaBok_Forfattare = new List<Bok_Forfattare>();
                BokSearchResultViewModel results = new BokSearchResultViewModel();


                aaBok.Add(a);

                foreach (var b in _myIBok_ForfattareRepository)
                {

                    if(a.BokID == b.BokID)
                    {

                        aaBok_Forfattare.Add(b);
                    }


                }

                results.Boks = aaBok;
                results.Bok_Forfattares = aaBok_Forfattare;

                _ViewBokSearch.Add(results);
            }


            return _ViewBokSearch;
        }

    } // Class
}

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-2