前台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);
}