entity framework - There are lots of records coming in my foreach loop, I want to display only two records -
@foreach (var item in model) { <div class="row leftimages"> <div class="col-md-6 col-xs-12 col-sm-12 innerimage"> <a href="@html.raw(html.encode(@html.displayfor(modelitem => item.dealurl)).replace("&", "&"))" target="_blank"><img src="@html.displayfor(modelitem => item.imageurl)" class="img-responsive1"> </a> </div> <div class="col-md-6 col-xs-12 col-sm-12"> <h4 class="tag">@html.displayfor(modelitem => item.title)</h4> <h5 class="greentext">@html.displayfor(modelitem => item.vendorname)</h5> <h5 class="freeship"></h5> @{ if (item.offerprice.hasvalue) { <h5 class="freeship">discount available of @html.displayfor(modelitem => item.discount)%</h5> <h4 class="price"> @html.displayfor(modelitem => item.offerprice) <span class="oldprice" style="text-decoration: line-through;"> @html.displayfor(modelitem => item.originalprice)</span></h4> } } </div> <div class="col-md-12"> <p class="paragraph"> @html.displayfor(modelitem => item.productdescription)</p> </div> </div> <div class="row blackstrip"> <div class="col-md-2 col-xs-3"> <h5 class="lefticons"><img src="images/like.png" ><a href="#">like</a></h5> </div> <div class="col-md-2 col-xs-3 icon"> <h5 class="lefticons"><img src="images/share.png"><a href="#">share</a></h5> </div> <div class="col-md-2 col-xs-3 icon"> <h5 class="lefticons"><img src="images/more.png"><a href="#">more</a></h5> </div> <div class="col-md-3 col-xs-3 col-md-offset-3 buy"> <h4 class="buynow"><a href="@html.raw(html.encode(@html.displayfor(modelitem => item.dealurl)).replace("&", "&"))" target="_blank">buy now</a></h4> </div> </div> }
you can use full power of linq
@foreach (var item in model.take(2))
better yet, want limit amount of data returned database in controller.
like db.yourdbset.where(x=> condition).take(2).tolist()