分享

JS & Jquery & Ajax & C#

 SanySmile 2012-11-14

    Jquerycs,js,ajax参数引用

     

    HTML引用cs对象

    @model UIH.PACS.Workstation.PatientRegister.Models.OrderModel

     

    @using (Html.BeginForm())

    {

    Model.cs代码的对象

    ………….

    }

     

    js引用html元素,应用Jquery

     

    $("")取界面元素

     

    对其相关属性进行操作

     

    JS引用cs对象,Ajax

     

    js端代码

    $(document).ready(function () {

            $.ajax({

                type: "Get",

                url: "/ClassName/MethodName",(此为函数URL

                data: null,

                dataType: "json",

                "async": false,                                  cs代码返回的值

                success: function (data) {

                    document.getElementById(data).checked = true;

                }

            });

        }); 

    cs端代码

     

    public JsonResult GetpatientClassType()

            {    

                           string  PatientClassTypeName = “”;

               return Json(PatientClassTypeName, JsonRequestBehavior.AllowGet);       

            }

    其中PatientClassTypeName为返回的值,其类型可自行设定

     

    CS引用JS的值并返回相应结果更新界面

    JS代码

     

    function UpdateDuration(searchValue) {(有界面触发的事件)

                    var condition = {};

                    condition["ProcedureTypeName"] = searchValue;(界面传入cs代码的值)

                    $.ajax({

                        type: "Get",

                        url: "/PatientRegister/UpdateStudyDuration",

                        data: condition,

                        dataType: "json",

                        "async": false,

                        success: function (data) {cs返回到js的值)

                            document.getElementById("Studyterm").value = data;(更新界面)

                            return true;

                        }

                    });

                }

    cs代码

     

    public JsonResult UpdateStudyDuration()

             {

                 string procedureTypeName = Request["ProcedureTypeName"];

                 string duration = "";

                 if (string.IsNullOrEmpty(duration))

                 {

                     duration = DataAccessHelper.GetStudyDurationByProcedureTypeName(procedureTypeName);

                 }

                 return Json(duration, JsonRequestBehavior.AllowGet);

             }

    JS传递数组对象

    js代码

     

    var ProcedureModelList = new Array();

           

                function ProcedureModel() {

                    this.ProcedureType = document.getElementById("ProcedureType").value;

                    this.Duration = document.getElementById("Studyterm").value;

                    this.StudyMethod = document.getElementById("StudyMethod").value;

                    this.PayType = document.getElementById("PayType").value;

                    this.Price = document.getElementById("ChargeNumber").value;

                    this.Room = document.getElementById("Room").value;

                    this.Category = document.getElementById("Category").value;

                    this.BigBodyPart = document.getElementById("BigBodyPart").value;

                    this.SmallBodyPart = document.getElementById("SmallBodyPart").value;

                    this.Protocol = document.getElementById("Protocol").value;

                }

     

    $.ajax({

                            type: "POST",

                            url: "/PatientRegister/GetProcedureModelGroup",

                            data: JSON.stringify(ProcedureModelList), 将数组转换为字符串对象

                            dataType: "html",

                            contentType: 'application/json'

     

                        });

    cs代码

     public void GetProcedureModelGroup(List<ProcedureViewModel> procedureModelList) (自动将string转换为需要转换的类型,此类型的字段需与 js 代码结构体字段完全一致

            {

                foreach (var procedureViewModel in procedureModelList)

                {

                    ProcedureViewModelGroup.Add(procedureViewModel);

                }

            }

     

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多