为什么小弟我的ASP.NET MVC4程序View在输出的时候直接输出Model的成员名
为什么我的ASP.NET MVC4程序View在输出的时候直接输出Model的成员名?
关键代码:
View里的头:
Controller里的Action:
Model里的调用:
关键代码:
View里的头:
@model List<CEALER.MVC.Models.Blog>
Controller里的Action:
public ActionResult Index()
{
Blog b = new Blog();
List<Blog> list = b.GetBlog(1);
//b.GetNewModel();
return View(list);
}
Model里的调用:
/// <summary>
/// 获取前n条实体集合
/// </summary>
/// <returns></returns>
public List<Blog> GetBlog(int n)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top " + n + " id,CreateUser,CreateTime,Pushed,Treaded,Commented,Wechated,Published,Title,SummaryText,SummaryImg,DetailContent ");
strSql.Append(" FROM [Blog] ");
DataSet ds = CEALER.Helper.MsSqlHelper.Query(strSql.ToString());
if (ds.Tables[0].Rows.Count > 0)
{
List<Blog> b = new List<Blog>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Blog b_Child = new Blog();
if (ds.Tables[0].Rows[i]["id"] != null && ds.Tables[0].Rows[i]["id"].ToString() != "")
{
b_Child.id = long.Parse(ds.Tables[0].Rows[i]["id"].ToString());
}
if (ds.Tables[0].Rows[i]["CreateUser"] != null)
{
b_Child.CreateUser = ds.Tables[0].Rows[i]["CreateUser"].ToString();
}
if (ds.Tables[0].Rows[i]["CreateTime"] != null && ds.Tables[0].Rows[i]["CreateTime"].ToString() != "")
{
b_Child.CreateTime = DateTime.Parse(ds.Tables[0].Rows[i]["CreateTime"].ToString());
}
if (ds.Tables[0].Rows[i]["Pushed"] != null && ds.Tables[0].Rows[i]["Pushed"].ToString() != "")
{
b_Child.Pushed = int.Parse(ds.Tables[0].Rows[i]["Pushed"].ToString());
}