读书不认真,什么都不知道,强行学MVC=》留言板是一切开始
做一个新闻发布系统
我想要的效果是
一: 新闻发布系统 3个数据表: 新闻数据,新闻类型,评论表
1、列表页 (所有)新闻类型+新闻标题 要输出,要遍历,要攻克
2、.详情页 (单个,需Id)只要输出一个
3、新闻评论列表 (单个,需Id)+评论
Model:
public class N_New
{
[Key]
public int ID { set; get; }
public int CategoryId { get; set; }
public string NewsTitle { get; set; }
public string NewsContent { get; set; }
public DateTime CreateTime { get; set; }
}
public class N_Category
{
[Key]
public int CategoryId { get; set; }
public int CategoryPid { get; set; }
public string CategoryName { get; set; }
}
public class N_Comment
{
[Key]
public int CommentId { get; set; }
public string CommentContent { get; set; }
public DateTime CreateTime { get; set; }
public int NewsId { get; set; }
public int UserId { get; set; }
}
二: 这东西解决如果是以前就是:
GET:Id =>
详情页 select N_New.*, N_Category.CategoryName from N_New,N_Category where N_New.ID=Id andN_Category.CategoryId=N_New.CategoryId
列表页 select N_New.*, N_Category.CategoryName from N_New,N_Category where N_Category.CategoryId=N_New.CategoryId
SQL查询后:
Id CategoryId NewsTitel NewsContent CreateTime CategoryName
1 1 2 3 2015-01-01 00:00:00.000 成人教育
2 2 test 我爱你 2015-01-01 00:00:00.000 职称考试
3 1 test test 2015-01-01 00:00:00.000 成人教育
4 4 4 4 2015-01-01 00:00:00.000 教师证培训
5 8 8 8 2015-01-01 00:00:00.000 电子商务证
三:思路出来
1.将sql改成 Linq
基础:Lambda表达式详细总结 http://blog.csdn.net/sf1520398083/article/details/49048427
详情页:
列表页:
2. 模型类传给视图(模型传值、Json传值)
① 模型传值 http://blog.csdn.net/sf1520398083/article/details/49048423
public class New_Cate {
public string New_idname { set; get; }
public N_New N_new { set; get; }
}
Controller:
View:
②Json传值 http://blog.csdn.net/sf1520398083/article/details/49053037
今天一个们给我建议,强行学LINq 不如把 ADO.NET基础打好,自己封装类
我瞬间知道自己做了很多无用功
开始 三层模式写MVC新闻