0

I am trying to display like this

var value = "Kartheek@gmail.com"

@Html.DisplayName(value)

Result is : com only.

why? what have to use in this case

here i am explaining more

My intention is to display content in very generic with grid.

public class Grid
{
    private  Type type { get; set; }

    public Grid(IEnumerable datasource)
    {
        if (datasource == null)
        {
            throw new ArgumentNullException("datasource");
        }

        this.type = datasource.GetType().GetGenericArguments().Single();
        this.Data = datasource;
    }

    public IEnumerable Data { get; set; }

    public IEnumerable<System.Reflection.PropertyInfo> Props
    {
        get
        {
            return this.type.GetProperties().AsEnumerable();
        }
    }
}

This is my c# class for grid. i am assigning values in to Grid.data and with viewbag i am sending grid data to view and then i am using this with in partial view

here my partial view code

  @if (Model != null)
{
    <table style="width: 100%">
        <thead>
            <tr>
                @foreach (var col in Model.Props)
                {

                    <th>@Html.Label(col.Name)</th>

                }
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.Data)
            {
                <tr>
                    @foreach (var prop in Model.Props)
                    {
                        var val = prop.GetValue(item, null).ToString();
                        <td>@Html.DisplayName(val)</td>

                    }
                    </tr>
                }
            </tbody>



    </table>
}

Finally i got answer with this.. But i am not satisfied with that bcz there is another good solution for it.

var val = "kartheek@gmail.com";
    <span>@val</span>
Kartheek
  • 281
  • 1
  • 6
  • 21
  • Why are you using DisplayName instead of DisplayFor? Also are you setting the variable in your controller or in the view? – PW Kad Apr 10 '13 at 16:31
  • Actually by reflection i am getting properties and values and making a table. there i can get only property and Value as a string expression. so i am using DisplayName only – Kartheek Apr 10 '13 at 16:35
  • It's reading your string as a nested property. See this question: http://stackoverflow.com/questions/11547631/html-label-to-display-email-address – Splendor Apr 10 '13 at 16:36
  • 1
    Can you post some code a little more specific to what you are doing? Just given the example above, I would recommend just using @value to display the value of the string. – Jeremy Apr 10 '13 at 16:39
  • Hey i edited my question in very detailed way – Kartheek Apr 11 '13 at 08:17
  • i added a alternative. but i am expecting a good answer. – Kartheek Apr 12 '13 at 07:01

0 Answers0