首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

为什么小弟我的ASP.NET MVC4程序View在输出的时候直接输出Model的成员名

2013-10-07 
为什么我的ASP.NET MVC4程序View在输出的时候直接输出Model的成员名?关键代码:View里的头:@model ListCEA

为什么我的ASP.NET MVC4程序View在输出的时候直接输出Model的成员名?


为什么小弟我的ASP.NET MVC4程序View在输出的时候直接输出Model的成员名

为什么小弟我的ASP.NET MVC4程序View在输出的时候直接输出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());
                    }


                    if (ds.Tables[0].Rows[i]["Treaded"] != null && ds.Tables[0].Rows[i]["Treaded"].ToString() != "")
                    {
                        b_Child.Treaded = int.Parse(ds.Tables[0].Rows[i]["Treaded"].ToString());
                    }
                    if (ds.Tables[0].Rows[i]["Commented"] != null && ds.Tables[0].Rows[i]["Commented"].ToString() != "")
                    {
                        b_Child.Commented = int.Parse(ds.Tables[0].Rows[i]["Commented"].ToString());
                    }
                    if (ds.Tables[0].Rows[i]["Wechated"] != null && ds.Tables[0].Rows[i]["Wechated"].ToString() != "")
                    {
                        b_Child.Wechated = int.Parse(ds.Tables[0].Rows[i]["Wechated"].ToString());
                    }
                    if (ds.Tables[0].Rows[i]["Published"] != null && ds.Tables[0].Rows[i]["Published"].ToString() != "")
                    {
                        b_Child.Published = int.Parse(ds.Tables[0].Rows[i]["Published"].ToString());
                    }
                    if (ds.Tables[0].Rows[i]["Title"] != null)
                    {
                        b_Child.Title = ds.Tables[0].Rows[i]["Title"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["SummaryText"] != null)
                    {
                        b_Child.SummaryText = ds.Tables[0].Rows[i]["SummaryText"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["SummaryImg"] != null)
                    {
                        b_Child.SummaryImg = ds.Tables[0].Rows[i]["SummaryImg"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["DetailContent"] != null)
                    {
                        b_Child.DetailContent = ds.Tables[0].Rows[i]["DetailContent"].ToString();
                    }
                    b.Add(b_Child);
                }
                return b;
            }


            else
                return null;
        }



实体:

#region Model
private long _id;
private string _createuser;
private DateTime _createtime= DateTime.Now;
private int _pushed=0;
private int _treaded=0;
private int _commented=0;
private int _wechated=0;
private int _published=1;
private string _title;
private string _summarytext;
private string _summaryimg;
private string _detailcontent;
/// <summary>
/// 
/// </summary>
public long id
{
set{ _id=value;}
get{return _id;}
}
/// <summary>
/// 
/// </summary>
public string CreateUser
{
set{ _createuser=value;}
get{return _createuser;}
}
/// <summary>
/// 
/// </summary>
public DateTime CreateTime
{
set{ _createtime=value;}
get{return _createtime;}
}
/// <summary>
/// 
/// </summary>
public int Pushed
{
set{ _pushed=value;}
get{return _pushed;}
}
/// <summary>
/// 
/// </summary>
public int Treaded
{
set{ _treaded=value;}
get{return _treaded;}
}
/// <summary>
/// 
/// </summary>
public int Commented
{
set{ _commented=value;}
get{return _commented;}
}
/// <summary>
/// 
/// </summary>
public int Wechated
{
set{ _wechated=value;}
get{return _wechated;}
}
/// <summary>
/// 
/// </summary>
public int Published
{
set{ _published=value;}
get{return _published;}
}
/// <summary>
/// 
/// </summary>
public string Title
{
set{ _title=value;}
get{return _title;}
}
/// <summary>
/// 
/// </summary>
public string SummaryText
{
set{ _summarytext=value;}
get{return _summarytext;}
}
/// <summary>
/// 
/// </summary>
public string SummaryImg
{
set{ _summaryimg=value;}
get{return _summaryimg;}
}
/// <summary>
/// 
/// </summary>
public string DetailContent
{
set{ _detailcontent=value;}
get{return _detailcontent;}
}
#endregion Model
mvc4 asp.net MVC C# ORM
[解决办法]
ModelItem 修改成 item
[解决办法]
Html.LabelFor改成Html.DisplayFor或直接@Model.字段名

热点排行