MVC Ajax,发布到控制器base64字符串

时间:2017-12-27 12:43:46

标签: c# json ajax asp.net-mvc

在我的项目中,我发送post json数据对象。该对象的一项是base64字符串。当base63字符串太长时,我的请求不会到达控制器。在我看来,由于参数的长度,它不起作用。我找不到任何解决方案。

        [HttpPost]
        [ValidateInput(false)]      
        public ActionResult Add(Page item)
        {
            if (item == null
                || string.IsNullOrEmpty(item.Title)
                || string.IsNullOrEmpty(item.SeoUrl))
                return Content(Serialization.JsonSerialize(new { Status = 400 }));

            return Content(Serialization.JsonSerialize(new { Status = 200, Result = PageRepository.Add(item) }));
        }

在控制器中,我编写了上面的代码,在视图中我编写了下面的代码

          var item = {
                Title: title,
                SeoUrl: seo,
                IsActive: isActive,
                Portals: portals,
                Content: content,
                Lang: pageLanguage,
                IsShown:isLock,
                MetaKeywords:keywords,
                MetaDescription:description
            }

            $.ajax({
                type: 'POST',
                url: '@Url.Action("Add", "Page")',
                data: JSON.stringify(item),                
                success: function(data) {
                    if (data.Result !== "SUCCEED") {
                        if (data.Result == "SEO_URL_EXISTS") {

                            toastr.warning('Böyle bir seo_url mevcuttur !!!');
                            return;
                        }
                        toastr.error('@Resources.Resource.Error_Unexpected');
                        return;
                    }
                    if (!isActive) {
                        toastr.success('@Resources.Resource.Success_PageSave');
                        return;
                    }
                    toastr.success('@Resources.Resource.Success_PageSaveAndPublish');
                    return;
                },
                error: function(error) {
                    toastr.error('@Resources.Resource.Error_Unexpected');
                    return;
                },
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                beforeSend: function() {
                    waitingDialog.show('@Resources.Resource.Waiting_PageUpdating');
                },
                complete: function() {
                    waitingDialog.hide();
                }
            });

在网络配置中,我在下面添加了

<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="999999999"/>
      </webServices>
    </scripting>
  </system.web.extensions>

内容项可能包含base64字符串。如何将这个jason数据发送到控制器,即使有很长的base64字符串。

这是错误:

  

使用JSON进行序列化或反序列化时出错   JavaScriptSerializer。字符串的长度超过了设置的值   在maxJsonLength属性上。参数名称:输入

0 个答案:

没有答案