zoukankan      html  css  js  c++  java
  • Invoke action which type of result is JsonResult on controller from view using Ajax or geJSon

     $.getJSON("/StoragePoint/ReadStoragePoint/", { id: $("#StoragePoint_Id").val() }, function (data) {
                            $("textarea[id='StoragePoint_AdditionalDetails']").val(data.AdditionalDetails);
                        }).success(function () { alert("second success"); })
                       .error(function () { alert("error"); })
                       .complete(function () { alert("complete"); });

    Or

     $.ajax({
                            type: 'POST',
                            url: '/StoragePoint/ReadStoragePoint',
                            data: { 'id': $("#StoragePoint_Id").val() },
                            dataType: 'json',
                            success: function (jsonData) { alert("Yes"); },
                            error: function () { alert('Error'); }
                        });

      [Authorise(PermissionIdentifier.ReadStoragePoint)]
            [AcceptVerbs(HttpVerbs.Get)]
            public JsonResult ReadStoragePoint(int id)
            {
                string additionalDetails = StoragePointRepository.ReadSingle(id).AdditionalDetails;
                var result = new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new
                              {
                                  AdditionalDetails = additionalDetails
                              },
                };
                return result;
            }

    JSon method:

  • 相关阅读:
    JS 跳转
    js 注意问题
    MySql 引擎
    openflashchart 与 FusionCharts 开发中使用
    MySql 字符串连接
    js 颜色选择器
    c#,winform,combobox联动 Virus
    c#,winform,验证输入内容,文本框,长度,errorprovider组件,方便,快捷 Virus
    c#,NHibernate,ASP.NET2.0,Winform Virus
    c#,小发现,关于程序当前目录的问题,Environment.CurrentDirectory,Application.StartupPath; Virus
  • 原文地址:https://www.cnblogs.com/Mac_Hui/p/2615309.html
Copyright © 2011-2022 走看看