0

我正在尝试这样显示

var value = "Kartheek@gmail.com"

@Html.DisplayName(value)

结果是:仅 com。

为什么?在这种情况下必须使用什么

我在这里解释更多

我的意图是用网格以非常通用的方式显示内容。

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();
        }
    }
}

这是我的网格 C# 类。我将值分配给 Grid.data 并使用 viewbag 我将网格数据发送到视图,然后我在部分视图中使用它

这是我的部分视图代码

  @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>
}

最后我得到了这个答案。但我对bcz不满意,还有另一个很好的解决方案。

var val = "kartheek@gmail.com";
    <span>@val</span>
4

0 回答 0