Generate ListView in MVC4
  • Hi please how i can generate ListView in MVC4 thank you So much ... :)
  • 3 Comments sorted by
  • Vote Up0Vote Down Jaguar777Jaguar777
    51.00 Karma Accepted Answer
    You can use table tag <table> or <ul> and do looping .Example below
    <span class="pun">&lt;</span><span class="pln">table </span><span class="kwd">class</span><span class="pun">=</span><span class="str">"content-wrapper"</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="str">&lt;tr&gt;</span><span class="pln">
    </span><span class="str">&lt;th&gt;</span><span class="pln">
    </span><span class="lit">@Html</span><span class="pun">.</span><span class="typ">DisplayName</span><span class="pun">(</span><span class="str">"Name"</span><span class="pun">)</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">th</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="str">&lt;th&gt;</span><span class="pln">
    </span><span class="lit">@Html</span><span class="pun">.</span><span class="typ">DisplayName</span><span class="pun">(</span><span class="str">"ID"</span><span class="pun">)</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">th</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="str">&lt;th&gt;</span><span class="pln">
    </span><span class="lit">@Html</span><span class="pun">.</span><span class="typ">DisplayName</span><span class="pun">(</span><span class="str">"Designation"</span><span class="pun">)</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">th</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="str">&lt;th&gt;</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">th</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">tr</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="lit">@foreach</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">var</span><span class="pln"> item </span><span class="kwd">in</span><span class="pln"> </span><span class="typ">Model</span><span class="pun">.</span><span class="pln">lstEmployees</span><span class="pun">)</span><span class="pln">
    </span><span class="pun">{</span><span class="pln">
    </span><span class="str">&lt;tr&gt;</span><span class="pln">
    </span><span class="str">&lt;td&gt;</span><span class="pln">
    </span><span class="lit">@Html</span><span class="pun">.</span><span class="typ">DisplayFor</span><span class="pun">(</span><span class="pln">modelItem </span><span class="pun">=&gt;</span><span class="pln"> item</span><span class="pun">.</span><span class="pln">name</span><span class="pun">)</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">td</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="str">&lt;td&gt;</span><span class="pln">
    </span><span class="lit">@Html</span><span class="pun">.</span><span class="typ">DisplayFor</span><span class="pun">(</span><span class="pln">modelItem </span><span class="pun">=&gt;</span><span class="pln"> item</span><span class="pun">.</span><span class="pln">id</span><span class="pun">)</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">td</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="str">&lt;td&gt;</span><span class="pln">
    </span><span class="lit">@Html</span><span class="pun">.</span><span class="typ">DisplayFor</span><span class="pun">(</span><span class="pln">modelItem </span><span class="pun">=&gt;</span><span class="pln"> item</span><span class="pun">.</span><span class="pln">designation</span><span class="pun">)</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">td</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="str">&lt;td&gt;</span><span class="pln">
    </span><span class="lit">@Html</span><span class="pun">.</span><span class="typ">ActionLink</span><span class="pun">(</span><span class="str">"Edit"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"Edit"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> id </span><span class="pun">=</span><span class="pln"> item</span><span class="pun">.</span><span class="pln">id </span><span class="pun">})</span><span class="pln">
    </span><span class="lit">@Html</span><span class="pun">.</span><span class="typ">ActionLink</span><span class="pun">(</span><span class="str">"Delete"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"Delete"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> id </span><span class="pun">=</span><span class="pln"> item</span><span class="pun">.</span><span class="pln">id </span><span class="pun">})</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">td</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="pun">&lt;/</span><span class="pln">tr</span><span class="pun">&gt;</span><span class="pln">
    </span><span class="pun">}</span>

  • <span class="tag">&lt;ul&gt;</span><span class="pln">
    @foreach (var message in Model.Messages)
    {
    </span><span class="tag">&lt;li&gt;</span><span class="pln">@message</span><span class="tag">&lt;/li&gt;</span><span class="pln">
    }
    </span><span class="tag">&lt;/ul&gt;</span>
  • Vote Up0Vote Down Jaguar777Jaguar777
    51.00 Karma Accepted Answer
    If you have money you can use telerik controls for asp.net mvc
    http://www.telerik.com/aspnet-mvc/listview


Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

    Optimum Creative