MVC Dapper+缓存

在这里插入图片描述

1、MVC控制器

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

namespace WebApplication37_MVC.Controllers
{
public class DefaultController : Controller
{
// GET: Default
public ActionResult Index()
{
return View();
}
public ActionResult Add(int id)
{
ViewBag.Id = id;
return View();
}
public ActionResult Info()
{
return View();
}

    public ActionResult fh()
    {
        return View();
    }
}

}

2、Index视图

@{
ViewBag.Title = “Index”;
}

Index

<tr>
    <td>类型</td>
    <td>名称</td>
    <td>信息</td>
    <td>审核</td>
    <td>操作</td>
</tr>
<tbody id="tb"></tbody>



<tr>
    <td>总共<span id="totalCount"></span>条数据</td>
    <td>第<span id="currentPage"></span>页</td>
    <td>共<span id="totalPage"></span>页</td>
    <td><a href="javascript:;" onclick="Show(1)">首页</a></td>
    <td><a href="javascript:;" onclick="Show(currentPage-1)">上一页</a></td>
    <td><a href="javascript:;" onclick="Show(currentPage+1)">下一页</a></td>
    <td><a href="javascript:;" onclick="Show(totalPage)">尾页</a></td>
</tr>


var currentPage = 1;
var totalPage = 1;
$(function () {
    Show(1);
})

function Show(page) {
    var obj = {};
    obj.pageSize = 3;
    obj.currentPage = page;
    $.ajax({
        url: "http://localhost:62202/api/Get",
        type: "get",
        data: obj,
        success: function (data) {
            $("#totalCount").html(data.totalCount);
            $("#totalPage").html(data.totalPage);
            $("#currentPage").html(data.currentPage);
            currentPage = data.currentPage;
            totalPage = data.totalPage;
            $("#tb").empty();
            $(data.list).each(function () {
                var line = "<tr>"
                line += "<td>" + '<a href="#" onclick="Add(' + this.Id + ')" >' + this.LX + '</a>' + "</td>";
                line += "<td>" + this.GG+"</td>";
                line += "<td>" + this.GZZD+"</td>";
                line += "<td>" + (this.SH == 0 ? "审核通过" : "驳回") +"</td>";
                line += "<td>" + '<a href="#">审核</a>'+"</td>";
                line += "</tr>";
                $("#tb").append(line);
            })
        }
    })
}
function Add(id) {
    location.href = "/Default/Add?id=" + id;
}

在这里插入图片描述

3、Add视图

@{
ViewBag.Title = “Add”;
}

Add

<tr>
    <td>类型</td>
    <td>
        <input type="text" id="lx" value="" />
        <input id="Hidden1" type="hidden" value="@ViewBag.Id" />
    </td>
</tr>
<tr>
    <td>名称</td>
    <td>
        <input type="text" id="gg" value="" />
    </td>
</tr>
<tr>
    <td>信息</td>
    <td>
        <input type="text" id="gzzd" value="" />
    </td>
</tr>
<tr>
    <td>审核</td>
    <td>
        <input type="text" id="sh" value="" />
    </td>
</tr>
<tr>
    <td>投资金额</td>
    <td>
        <input type="text" id="tzje" value="" />
    </td>
</tr>
<tr>
    <td>
        <input type="button" name="name" value="提交" onclick="Add(),location.href = 'Info'" />
    </td>
</tr>




$(function () {
    Fan();
})
function Fan() {
    $.ajax({
        url: "http://localhost:62202/api/UptInfo?Id=" + $("#Hidden1").val(),
        type: "get",
        dataType: "json",
        success: function (d) {

            $("#lx").val(d.LX);
            $("#gg").val(d.GG);
            $("#gzzd").val(d.GZZD);
            $("#sh").val(d.SH);
        }
    })
}
function Add() {
    var obj = {};
    obj.LX = $("#lx").val();
    obj.GG = $("#gg").val();
    obj.GZZD = $("#gzzd").val();
    obj.SH = $("#sh").val();
    obj.TZ = $("#tzje").val();
    $.ajax({
        url: "http://localhost:62202/api/AddUserInfo",
        type: "post",
        data: obj,
        success: function (data) {
            if (data > 0) {
                alert("添加成功");
            }
            else {
                alert("添加失败");
            }
        }
    })
}

在这里插入图片描述

4、Info视图

@{
ViewBag.Title = “Info”;
}

Info

<tr>
    <td>类型</td>
    <td>名称</td>
    <td>信息</td>
    <td>审核</td>
    <td>投资</td>
</tr>
<tbody id="tb"></tbody>



<tr>
    <td>
        <input id="Hidden1" type="hidden" />

        <input type="button" name="name" value="确认投资" onclick="Add(),location.href = 'fh'"  />
    </td>
</tr>


$(function () {
    Show();
})
function Show() {
    $.ajax({
        url: "http://localhost:62202/api/GetUserInfos?userKey=YhxxModel",
        type: "get",
        success: function (data) {
            $("#tb").empty();
            $(data).each(function () {
                var line = "<tr>"
                line += "<td><span id='lx'>" + this.LX + "</span></td>";
                line += "<td><span id='GG'>" + this.GG + "</span></td>";
                line += "<td><span id='GZZD'>" + this.GZZD + "</span></td>";
                line += "<td><span id='TZ'>" + this.TZ + "</span></td>";
                line += "<td><span id='SH'>" + (this.SH == 0 ? "审核通过" : "驳回") + "</span></td>";
                line += "</tr>";
                $("#tb").append(line);

            })
        }
    })
}


function Add() {
    var obj = {};
    obj.LX = $("#lx").text();
    obj.GG = $("#GG").text();
    obj.GZZD = $("#GZZD").text();
    obj.SH = $("#SH").text();
    obj.TZ = $("#TZ").text();
    $.ajax({
        url: "http://localhost:62202/api/Add",
        type: "post",
        data: obj,
        success: function (data) {
            if (data > 0) {
                alert("添加成功");
            }
            else {
                alert("添加失败");
            }
        }
    })
}

在这里插入图片描述

5、FH视图

@{
ViewBag.Title = “fh”;
}

fh

     var i = 5;
    var intervalid;
    intervalid = setInterval("fun()", 1000);
    function fun() {
        if (i == 0) {
            location.href = "Index";    //返回页面
            clearInterval(intervalid);
        }
        document.getElementById("mes").innerHTML = i;
        i--;
    }</script>


<div class="cg_fhdiv m_t">
    <p>恭喜,操作成功!</p>
    系统<second id="mes">5</second>秒后自动返回!<br />

    <button type="submit" class="submit btn">返&nbsp;&nbsp;回</button>
</div>

在这里插入图片描述

©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页