加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

JsonResult&FileResult应用实例

发布时间:2020-12-16 19:14:34 所属栏目:百科 来源:网络整理
导读:JsonResult应用实例 情景:两个下拉选择,后一个下拉选择根据前一个的选择来生成选项。 controller [ HttpPost ] public JsonResult GetChildrenTypes (string parent) { var result = client. ListProductTypeSub ( parent); if (! result .Success ) { JsE
JsonResult应用实例
情景:两个下拉选择,后一个下拉选择根据前一个的选择来生成选项。

controller
[ HttpPost ]
        public JsonResult GetChildrenTypes (string parent)
        {
            var result = client. ListProductTypeSub ( parent);
                    if (! result .Success )
                    {
                        JsError (result . Message);
                    }
            var data = new JsonResult ();
            data .Data = result .Result ;
            return data ;
        }

 
view
@{ var itemsProductType = new SelectList ( ViewBag. ListProductType,"Key","Value",Model . ProductType); }
        < label for="ProductType"> 产品类别 </label > @ Html. DropDownListFor ( m => m . ProductType,@itemsProductType,"请选择",new{@class="input-medium"} ) 

        < label for="ProductTypeSub"> 产品类型</ label>< select id = "ProductTypeSub" name = "ProductTypeSub" class = "input-medium" ></select >


 
js
 $("#ProductType").change(function () {
                changeDropdownList("#ProductType","#ProductTypeSub");
            });

 var changeDropdownList = function (source,target) {
        if ($(source).val() !== "") {
            $.ajax({
                type: "POST",url: "/BillingBusiness/GetChildrenTypes",data: { parent: $(source).val() },success: function (data) {
                    var innerHtml = "<option value="">请选择</option>";
                    if (data!=null) {
                        for (var item in data) {
                            innerHtml += "<option value="" + item + "">" + data[item] + "</option>";
                        }
                    }
                    $(target).html(innerHtml);

                    var selectValue = "";
                    if (target == "ProductType") {
                        selectValue = config.ProductType;
                    }
                    if (selectValue !== "") {
                        $(target).val(selectValue);
                    }
                }
            });
        } else {
            $(target).html("<option value="">请选择</option>");
        }
    };//changeDropdownList() END




FileResult应用实例
导出excel。


controller
//导出业务帐
         [ HttpGet ]
         public FileResult ExportBusinessAccount (BusinessAccountParam param)
         {
             param .ClientNo = "tst" ;
             var result = client .ExportBusinessAccount ( param);
             if (! result .Success )
             {
                 JsError (result . Message);
             }
             return File ( result. Result .StreamBytes,"application/ms-excel","BusinessAccountList.xls" );		
		//第一个参数为二进制字节流
               //返回zip的话  return File ( result. Result .StreamBytes,"application/octet-stream","BusinessAccountList.zip" );
         }

js
$ ( "#exportExcel" ).click ( function () {
           $ ("#frmSearch" ). attr( "action","ExportBusinessAccount" );
            $ ("#frmSearch" ). submit();
    });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读