不显示数据

时间:2016-09-09 10:26:47

标签: asp.net-mvc oop collections

任何人都可以帮我这个。

public Dictionary<string,object> UserExistOrNot()
    {
        Dictionary<string, object> result = new Dictionary<string, object>();
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
            string _userName = "user01";
            string _password = "user";
            string sqlQuery = "select * from [User] t0 inner join UserProfile t1 on t0.UserId=t1.UserId where t0.UserName='" + _userName + "' and t0.Password='" + _password+"'";
            SqlDataAdapter da = new SqlDataAdapter(sqlQuery, con);
            DataSet ds = new DataSet();
            da.Fill(ds, "usertable");
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    result.Add("UserId", dr["UserId"]);
                    result.Add("UserName", dr["UserName"]);
                    result.Add("Password", dr["Password"]);
                    result.Add("Email", dr["Email"]);
                    result.Add("Mobile", dr["Mobile"]);
                    result.Add("Gender", dr["Gender"]);
                    result.Add("Street1", dr["Street1"]);
                    result.Add("Street2", dr["Street2"]);
                    result.Add("Street3", dr["Street3"]);
                    result.Add("Street4", dr["Street4"]);
                    result.Add("CityId", dr["CityId"]);
                    result.Add("StateId", dr["StateId"]);
                    result.Add("Country", dr["Country"]);
                }
            }
            else
                return result;

        return result;
    }

输出显示如下:

System.Collections.Generic.Dictionary`2[System.String,System.Object]


我想显示数据而不是类型

1 个答案:

答案 0 :(得分:0)

浏览器理解纯文本,xml或html,但不理解复杂类型,因此你必须返回其中一种类型,或者创建一个带有模型Dictionary的视图,并迭代throw键和vslues来查看它。