zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    html5 本地存储
    javascript 中的 this 关键字详解
    重绘和回流
    javascript 的预解释机制
    zepto.js 实现原理解析
    python3.6新特性
    python面试终极准备
    科大讯飞语音合成api
    智能儿童玩具
    MySQL与MongoDB
  • 原文地址:https://www.cnblogs.com/lingr/p/5563476.html
Copyright © 2011-2022 走看看