How to display items in View using Reflection in MVC

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

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;}
</style>

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


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

regards

Baiju




Responses

(No response found.)

Login to post response