mvc json实现选择列表之后,发布功能

背景: mvc  json实现选择列表之后,发布功能

功能:当选择列表ck之后,用json拼接成一个字符串包含:id与是否选中两列,然后在服务器端进行批量修给数据库数据,最后修改成功之后,给页面提示的功能

 从客户端到服务器端用的是json传输,从服务器端传输到客户端哦是json传输。

html:

@model Glodon.Collaboration.WebUI.Models.MainExpertModels
@{
    ViewBag.Title = " 专家管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="/Scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript">
    function GetJson() {
        var Jsons = "[";
        $('input[id="item_Ispublish"]').each(function () {

            var trJson;
            var Ispublish = $(this).attr("checked");
            var id;
            id = $(this).nextAll('input[id="item_id"]').val();
            trJson = "'Id':" + "'" + id + "',";
            if (Ispublish == "checked") {
                Ispublish = true;
            }
            else if (Ispublish == undefined) {
                Ispublish = false;
            }
            trJson = trJson + "'Ispublish':" + "'" + Ispublish + "'";

            trJson = "{" + trJson + "}";
            Jsons += trJson + ",";
        });

        //去掉最后一组数据后面的“,”
        if (Jsons.lastIndexOf(",") == Jsons.length - 1)
            Jsons = Jsons.substring(0, Jsons.length - 1);
        Jsons = Jsons + "]";
        return Jsons;
    }

    function listtext() {    
        var json = GetJson();
        $.ajax({
            url: "/Expert/Goto_Increased_Publish",
            dataType: "json",
            data: "data=" + json,
            type: "POST",
            success: function (data) {
                var arr = eval('(' + data + ')').result;              
                switch (arr) {
                    case '1':
                        alert("发布成功");
                        return;
                    default: alert("发布失败"); return;
                }
            }
        });
    }       
</script>
<h2>
    专家管理</h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true) 
    <fieldset>
        <legend>专家管理</legend>
        <table
          @if (Model.PageFlag == "Increased" || Model.PageFlag == "Published" || Model.PageFlag == "IncreasedCity" || Model.PageFlag == "PublishedCity")
          { 
             @Html.Raw("style=\"width: 100%;display:none;\"")   
          }
          else
          {
           @Html.Raw("style=\"width: 100%;\"")   
          }>
            <tr>
                <td align="right">
                    姓名
                </td>
                <td>@Html.TextBoxFor(m => m.name, new { style = "width:120px" })
                </td>
                <td align="right">
                    年龄
                </td>
                <td>
                    @Html.TextBoxFor(m => m.age, new { style = "width:120px" })
                </td>
                <td align="right">
                    性别
                </td>
                <td>
                    @if (Model != null)
                    {
                        @Html.DropDownListFor(m => m.sex, new SelectList(Model.SexSource, "Key", "Value", " == 选择类型 == "))
                    }
                </td>
            </tr>
            <tr>
                <td align="right">
                    专业
                </td>
                <td>
                    @Html.TextBoxFor(m => m.speciality, new { style = "width:120px" })
                </td>
                <td align="right">
                    机构名称
                </td>
                <td>
                    @Html.TextBoxFor(m => m.jigoumingcheng, new { style = "width:120px" })
                </td>
            </tr>
            <tr>
                <td align="right">
                    入库时间
                </td>
                <td>
                    <input id="begin" value=@Model.begindate type="text" onClick="WdatePicker()"style=" width:120px"/>至
                </td>
                <td>
                    <input id="end" value=@Model.enddate type="text" onClick="WdatePicker()" style=" width:120px"/>
                </td>
            </tr>
            <tr>
                <td colspan="6">
                    <p align="center">
                        <input type="submit" id="summbitpublish" value="查  询" />
                    </p>
                </td>
            </tr>
        </table>
        <table
          @if (Model.PageFlag == "Browser")
          { 
                @Html.Raw("style=\"width: 100%;display:none;\"") 
          }
          else
          {
               @Html.Raw("style=\"width: 100%;\"")
          }>
            <tr>
                <td>
                    <a href="#" οnclick="window.open('./Edit?hrId=','','height=600,width=800,fullscreen=no,resizable=yes,scrollbars=no,top=350,left=500')">
                        添 加</a> <a id="searchsubmit" οnclick="listtext()">发布</a>
                </td>
            </tr>
        </table>
        <table cellspacing="0" cellpadding="4" id="GridView1" style="color: #333333; width: 100%;
            border-collapse: collapse;">
            <tr style="color: White; background-color: #507CD1; font-weight: bold;">
                <th style="width: 80; text-align: center" scope="col">
                    序号
                </th>
                <th style="width: 80; text-align: center" scope="col">
                    姓名
                </th>
                <th style="width: 80; text-align: center" scope="col">
                    性别
                </th>
                <th style="width: 80; text-align: center" scope="col">
                    年龄
                </th>
                <th style="width: 80; text-align: center" scope="col">
                    专业
                </th>
                <th style="width: 80; text-align: center" scope="col">
                    入库时间
                </th>
                <th style="width: 80; text-align: center" scope="col">
                    联系方式
                </th>
                <th style="width: 80; text-align: center" scope="col">
                    上报单位
                </th>
                <th style="width: 80; text-align: center" scope="col">
                    上报时间
                </th>
                @if (Model.PageFlag != "Browser" || Model.PageFlag != "Published")
                {
                    <th scope="col" style="width: 40; text-align: center">
                        发布
                    </th>
                }
                @if (Model.PageFlag != "Browser")
                {
                    <th scope="col" style="width: 40; text-align: center">
                        操作
                    </th>
                }
            </tr>
            @if (Model.ExpertModelsList != null)
            {
                int i = 0;
                foreach (var item in Model.ExpertModelsList)
                {                   
                <tr
                    @if (i++ % 2 == 1)
                    {
                        @Html.Raw("style=\"background-color: #EFF3FB;\"")
                    }
                    else
                    {
                        @Html.Raw("style=\"background-color: White;\"")
                    }>
                    <td>
                        @Html.Hidden("item.HrId", item.HrId, new { id = "item.HrId" })
                        @Html.DisplayFor(modelItem => item.xuhao)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.name)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.SexStr)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.age)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.speciality)
                    </td>
                    <td>
                        @(item.Birthday == null ? "" : item.CreateTime.Value.ToShortDateString())
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.phone)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.JigouId)
                    </td>
                    <td>
                        @(item.Birthday == null ? "" : item.PublishTime.Value.ToShortDateString())
                    </td>
                    @if (Model.PageFlag != "Browser" && Model.PageFlag != "Published")
                    {
                        <td>
                            @Html.CheckBox("item.Ispublish", item.Ispublish)
                            @Html.Hidden("item.id", item.HrId)
                        </td>
                    }
                    @if (Model.PageFlag != "Browser")
                    {
                        <td>
                            <a href="#"  οnclick="window.open('./Edit?hrId=@item.HrId','','height=600,width=800,fullscreen=no,resizable=yes,scrollbars=yes,top=350,left=500')">
                                编辑</a>| <a href="#" οnclick="window.open('./Detail?hrId=@item.HrId','','height=600,width=800,fullscreen=no,resizable=yes,scrollbars=yes,top=350,left=500')">
                                    详情</a>
                            @if (Model.PageFlag == "Published")
                            {
                                <a  href="Has_Published_Delete?id=@item.HrId"  οnclick='return confirm("确定要删除吗?")'>|删除</a>
                            }
                            else
                            {
                                <a  href="Goto_Increased_Delete?id=@item.HrId"οnclick='return confirm("确定要删除吗?")'>|删除</a>
                            }
                        </td>
                    }
                </tr>
                }
                <tr>
                    <td colspan="11">
                        <div class="Pagination">@Glodon.Collaboration.WebUI.HtmlExtension.Pagination(this.Html, (int)ViewBag.PageSize, (int)ViewBag.Index,
                    (int)ViewBag.RecordCount, new { @ViewType = 0, @Identifier = "page", @Encrypt = false })</div>
                    </td>
                </tr>
            }
        </table>
    </fieldset>
}

control:
        [HttpPost]
        public JsonResult Goto_Increased_Publish(string data)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            List<PublishModel> list = js.Deserialize<List<PublishModel>>(data);
            foreach (var s in list)
            {
                var id = s.Id;
                var isPublish = s.Ispublish;           
                var expert = _repo.Get<TabHr>(id);
                expert.Ispublish = isPublish;
                _repo.Save();
            }
            string Data = "{'result':'1'}";
            return Json(Data);   
        }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

18妹

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

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

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

打赏作者

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

抵扣说明:

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

余额充值