將後台的Json數據返回到前台

Posted on 2015-07-29 16:09  qhy1277  阅读(356)  评论(0编辑  收藏  举报

前台JS代碼

$.post('/Book/GetBookClassIDByName', { BookName: "旅遊手冊" }, function (data) {

                if (data != 0) {                     if (parseInt($("#BookClassID").val()) == data) {                         $("#dinfo").find("h4").html("旅遊手冊-進階資料");                         $("#trTeamNo").show();

                        //$("#trTeamNo").attr("style", "");                     } else {                         $("#trTeamNo").hide();                         //$("#trTeamNo").attr("style", "display: none");                         $("#dinfo").find("h4").html("代編-進階資料");                     }                 } else {                     $("#trTeamNo").hide();                     //$("#trTeamNo").attr("style", "display: none");                     $("#dinfo").find("h4").html("代編-進階資料");                 }             });

 

後台controller代碼:

 

 public JsonResult GetBookClassIDByName(string BookName)
        {
            int BookClassID = BookClassRepository.getBookClassIdByName(BookName);
            return Json(BookClassID);
            //IEnumerable<int> IbookClassList = BookClassRepository.getBookClassList();
            //return Json(IbookClassList.Where(x => x.ParentID == Pid), JsonRequestBehavior.AllowGet);
        }

Copyright © 2024 qhy1277
Powered by .NET 9.0 on Kubernetes