简体   繁体   中英

How to display list returned to strongly typed partial view

I have a form with a lookup. I want to display the results of the lookup in the form so the user can select a result and then it would populate a field on the form (to be submitted with the form). I have a partial view in the form with the search box. That passes a string (pacupc) to the controller. However, I don't know how to display the list that's being return to the partial view. In my controller:

PriceAssociationLookup pacRep = new PriceAssociationLookup();

return PartialView("_PacSearchResultsPartial", pacRep.GetPacs(pacupc));

definition for GetPacs in class:

IEnumerable<IPriceAssociationLookupRepository> IPriceAssociationLookupRepository.GetPacs(string upc)
{
    using (PortalDataEntities entities = new PortalDataEntities())
    {
        var priceAssociationLookups = (from priceassociationlookup in entities.PriceAssociationLookups
                                       where priceassociationlookup.Upc == upc
                                       select priceassociationlookup).ToList();

        return priceAssociationLookups;
    }

}

and the partial view the lookup results are being sent to:

@model List<Portal.BusinessModel.Entities.PriceAssociationLookup>
@{
    //How to display the list of results?
}

You simply loop them like this:

@model List<Portal.BusinessModel.Entities.PriceAssociationLookup>
@foreach(var price in Model)
{
    @price.Upc
}

You can output any of your properties by using the @price.Property notation.

Please note if you are posting the items back you need to use a for loop and index them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM