asp.net mvc - How to pass an IEnumerable or queryable list of properties from Controller to View -


i hope can me out, struggling issue days now.. programming web application grant users access coupon codes online shops.

what use: vb.net, entity framework, mvc (mvvm), ms sql server.

this first post on , native language not english, nor advanced hobby programmer, pls accept apologies in case there appropriate answer not able find due not knowing search :/

i have few tables linked many-to-many relations via relation table: tblmerchantsinfo, tblproductsinfo,tblcouponsinfo, tblrelations

i have set view expect viewmodel contains neccessary information view useful possible, cannot figure out how pass list(?) of tbl.productsinfo.prodcategoryname view via viewbag or viewdata.

from viewmodel can list of categories exist in database, however, list contains duplicates avoid can set actionlink each distinct category.

view:

<%@ page inherits="system.web.mvc.viewpage(of rabattverwaltung.couponinfoviewmodellist)" language="vb" %> <!doctype html> <html> <head id="head1" runat="server">     <title>index</title>     <!--[more stuff going on here]--> </head>  <body>     filter categories:     <%for each cat in model.couponinfoviewmodel%>         <a href="/searchcoupons/index/?category=<%= cat.productcategory%>"> <%= cat.productcategory%>         </a>     <%next%> </body> 

would give me list of categories, including duplicates. that´s why thought of passing ienumerable view using viewbag or viewdata.

i (try to?) create in controller:

dim catlist new list(of ienumerable) each distinctcat in (from prod in database.tblproducts select prod)     catlist .add(distinctcat .prodcategory.distinct) next viewbag.allcategorieslist = catlist 

this results in error "value cannot null.". when delete "distinct" term create list , pass view. not able figure out how loop through list , find distinct items :/

any suggestions highly appreciated.

edit: how distinct categories out of viewmodel instead of passing list via viewbag? maybe better way, guess :/

i found solution problem :'d dayumn, issue buggin me o.Ô

just in case future noob have same problem had:

in controller have this:

 dim categorylist new list(of ienumerable)     each distinctcategory in (from prod in database.tblproducts select prod.prodcategor< distinct)         categorylist .add(distinctcategor)     next      viewbag.allcategorieslist = categorylist  

while in view have:

<% each cat in viewbag.allcategorieslist %>                         <a href="/index/?category=<%= cat%>"> <%=cat%></a>                     <%next%> 

now can select link view pass filter category , select products in particular category. couldn't figure out how these unique values out of viewmodel, thus, happy see suggestions not using viewbag (y)

happy


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -