MVC系列-11.两表联合-发表文章

1.在models下新建Article.cs

wps680A.tmp

2.改造Account.cs

wps681B.tmp

3.在controller下新建控制器Article

(1)增加两action--限定需要登录才能打开

[Authorize]

public ActionResult Add()

        {

return View();

        }

        [HttpPost]

public ActionResult Add(Models.Article art)

        {

return View();

        }

4.下载百度的编辑器ueditor插件

http://ueditor.baidu.com/website/download.html

(1)把文件包放到项目根目录下。

(2)修改umeditor.config.Js中的路径为插件文件夹在项目中的路径

window.UMEDITOR_HOME_URL = "/Ueditor/";//修改本处 路径

(3)根据需要自行修改imageUp.Ashx中的图片文件上传路径

string pathbase = "/upload/";       

(4)uploader.Cs类的属性【生成操作】由【编译】改为【内容】。

5.为第一个Add增加view(视图)---Add.cshtml

(1)增加ueditor需要的js和css引用

wps681C.tmp

(2)实例化编辑器

(3)增加表单、标题输入框、提交按钮等。ContentBody内容如下:

wps682D.tmp

(4)改造accountcontroller

1)Logout()里加上 Session["UserID"] = null;//新增

2)Login里新增 Session["UserID"] = acc.First().ID;//新增

wps682E.tmp

EF查询参考资料:

http://www.cnblogs.com/liyanwei/p/d9f9b690e71b14bcaf765a92b442e8e9.html

(5)打开dal下的AccountContext

增加字段: public DbSet<MVCDemo.Models.Article> Articles { get; set; }

(6)打开ArticleController

增加字段:private DAL.AccountContext db = new DAL.AccountContext();

(7)编写ArticleController--add方法

wps683F.tmp

posted @ 2016-06-06 13:11  chenglingr  阅读(148)  评论(0编辑  收藏  举报
生活在继续,我们需要活着