Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi I am write some code.when i want to get some values from table and show in list . so Please help me the solve this problem...
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<table>
   <tr>
      <th>GenreId</th>
      <th>Name</th>
      <th>Description</th>
   </tr>
 @foreach (var item in Model) 
   {
    <tr>
        <td>@item.GenreId</td>
       <td>@item.Name</td>
        <td style="width:300px">@item.Description</td>
    </tr>
  }  
</table>
<pre>
Posted
Comments
ArunRajendra 15-Jul-14 3:07am    
In which line are you getting error?
ShoaibMehsud 15-Jul-14 3:18am    
@foreach loop
ArunRajendra 15-Jul-14 3:21am    
Ok I guess solution 1 should work.
ShoaibMehsud 15-Jul-14 3:23am    
not work :(
ArunRajendra 15-Jul-14 4:58am    
Can you post your controller code?

please add this code at top of u r view-->@model your applicationname.model.modelclasssname I think it works for your's...
 
Share this answer
 
Comments
ShoaibMehsud 15-Jul-14 3:47am    
no work :(
Hi,

Hopefully, Problem is here
C#
@foreach (var item in Model)
  {

Please fetch all data in list and put list into tempdata then at view page, put this into list and use that list to populate the table data.
 
Share this answer
 
Comments
Sarvesh Kumar Gupta 15-Jul-14 5:12am    
Who have downvoted this, please put some comment before doing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900