将c#字典输出应用于html表

Win*_*nkz -3 html c# dictionary code-behind

我有一个字符串与字符串和int我想解析字典字符串和内联到一个HTML表格,如果可能的话?

protected void Page_Load(object sender, EventArgs e)
    {

        Dictionary<string, int> userMediaList = new Dictionary<string, int>();
        userMediaList.Add("Die Hard", 5);
        userMediaList.Add("Die Hard II", 3);
        userMediaList.Add("Die Hard III", 2);
        userMediaList.Add("Ringenes Herre", 4);
        userMediaList.Add("Ringenes Herre II", 1);
        userMediaList.Add("Ringenes Herre III", 5);

        var sortUserMediaList = from entry in userMediaList orderby entry.Value ascending select entry;

    }
Run Code Online (Sandbox Code Playgroud)

所以我想要的是将它添加到网站上的表格中.

因此,对于表格中的每个框,将显示电影的名称和电影的评级.

dav*_*v_i 6

由于您没有说明您使用的是哪种技术,因此这是一种通用方式:

var trs = dictionary.Select(a => String.Format("<tr><td>{0}</td><td>{1}</td></tr>", a.Key, a.Value));

var tableContents = String.Concat(trs);

var table = "<table>" + tableContents + "</table>";
Run Code Online (Sandbox Code Playgroud)