How to display items in View using Reflection in MVC

Posted by Klbaiju under ASP.NET MVC on 11/7/2014 | Points: 10 | Views : 830 | Status : [Member] | Replies : 0

Following is a working code for displaying records in view

@using MvcWcf.ServiceReference1
@model IEnumerable<WcfService.MyAddress>

<style type="text/css">
table,tr,td{border:1px solid black;border-collapse:collapse;}

<td>@Html.DisplayNameFor(model => model.Address1)</td><td>@Html.DisplayNameFor(model => model.City)</td>
@foreach (var item in Model)
<tr><td>@Html.DisplayFor(modelItem => item.Address1)</td><td>@Html.DisplayFor(modelItem => item.City)</td>

in the above code i wrote table header name and fieldnames manually.because i know i the field names.

how to write the table header name and field names automatically using reflection




(No response found.)

Login to post response