asp.net MVC5简单小例子

3 篇文章 0 订阅
3 篇文章 1 订阅

在2019年底项目结束,因为是在某通外包公司,所以项目组不需要我了,只能每天去某通正常打卡上下班(因为快过年了,所有打算过完年在找工作现在先在这里闲着学习充电)。外包公司不可能会全额公司养着闲人。。。。。在这里告诫大家,一定别去外包。

自己写了点东西,项目结构如图:数据库用的是sqlite数据库,因为这样可以让看到这个项目的人直接调试程序,看到效果。

.db文件就是数据库,但是使用的时候,需要引用sqlite.dll

文件在---AHao\AHao.Web\bin目录下

这个项目是一个简单登录-注销-发表内容-删除内容的程序。有兴趣的可以自行扩展其他功能,由于作者对前端css样式不太熟悉,界面比较丑,但是功能都有,大家见谅。

项目的主页展示如上图

数据库连接字符串,要根据自己的实际路径配置。在web.config文件中。如图:

源码下载地址放到百度网盘里了,因为csdn下载需要积分

部分代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AHao.Web.Controllers
{
    /// <summary>
    /// 发表文章
    /// </summary>
    public class PostController : Controller
    {
        public ActionResult Index(int id)
        {
            //根据id去数据库查找对应的信息
            Model.Post post = postBll.GetModel(id);//没有缓存
            //Model.Post post = postBll.GetModelByCache(id);//从缓存中取数据
            ViewData["article"] = post;
            return View();
        }
        public ActionResult Publish()//发表
        {
            return View();
        }
        Business.Post postBll = new Business.Post();
        public ActionResult DoPublish()
        {
            string title = Request.Form["title"];
            string content = Request.Form["content"];
            Model.User user = (Model.User)Session["user"];
            Model.Post post = new Model.Post
            {
                Title = title + "-" + user.Name,
                Content = content,
                AddTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
            int id = postBll.Add(post);
            return new RedirectResult("/Home/Index"); //RedirectToAction("Index", "Post", new { id = id });
        }
        public ActionResult Delte(int id)
        {
            bool res = true;
            res = postBll.Delete(id);
            if (res)
            {
                return new RedirectResult("/Home/Index");
            }
            else
            {
                return new RedirectResult("/Account/Index");
            }
        }
    }
}

下载地址链接:https://pan.baidu.com/s/1VcxTlFbgJ8YVXb5SPqsTMw 
提取码:9rh7 

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你懂的11

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值