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:

  • 相关阅读:
    win10+PHP 安装memcache
    win10+PHP 安装redis
    一个github搞定微信小程序支付系列
    Linux下新建一个站点
    Linux下更改mysql版本
    零基础配置Linux服务器环境
    手把手教你使用ueditor
    react学习三
    react学习二 生命周期
    window.location.replace和window.location.href区别
  • 原文地址:https://www.cnblogs.com/Mac_Hui/p/2615309.html
Copyright © 2011-2022 走看看