2012-10-19 60 views
3

我用编辑器在我的页面时,我想用AJAX来更新我的价值观,我得到这个错误: 遗漏的类型错误:转换圆形结构,以JSON转换圆形结构,以JSON的HTML。发送值控制器

这是我的看法:

@{ 
    Layout = null; 
} 

<html> 
<head> 
    <meta name="viewport" content="width=device-width" /> 
    <title>Edit</title> 

    <script type="text/javascript"> 
     $(function() { 
      $("#editor").kendoEditor({ 
       value: "@Html.Raw(Model.Content)" 
      }); 
      $("#back").click(function() { 
       $.get('@Url.Action("Index", "Editor")', { siteId: "@ViewBag.SiteId", widgetId: "@Model.WidgetId" }, 
           function (data) { 
            $("div[data-role='popup']").remove(); 
            var indexContent = $(data).find("#content"); 
            $(indexContent).fadeIn(101); 
            $("#content").replaceWith(indexContent); 
           }); 


      }); 
      var content = $("#editor").data("kendoEditor"); 
      $("#save").click(function() { 
       var editor = { 
        Id: 1, 
        Content: content, 
        Title: 1, 
       }; 

       $.ajax({ 
        url: '@Url.Action("Update", "Editor")', 
        type: "POST", 
        contentType: "application/json charset=UTF-8", 
        dataType: "json", 
        data: JSON.stringify(editor), 

       }); 
    }); 
     }); 
    </script> 
</head> 
<body> 
    <div id="editorContainer"> 
     <div id="editorContent"> 
      <input type="text" value="@Model.Title" style="width:300px" id="title"/> 
      <textarea id="editor" rows="10" cols="30" style="width: 740px; height: 440px"> 
</textarea> 
     </div> 


    </div> 
    <button id="save">ذخیره</button> 
    <button id="back">بازگشت</button> 
</body> 
</html> 

在我看来我发布价值与jquery ajax但我得到错误。

回答

1
saveButton.click(function() { 
       var model = { 
        Id: '@Model.Id', 
        Content: editor.data("kendoEditor").encodedValue(), 
        Title: $('#title').val(), 
       }; 

       $.ajax({ 
        url: '@Url.Action("Update", "Editor")', 
        type: "POST", 
        contentType: "application/json charset=UTF-8", 
        dataType: "json", 
        data: JSON.stringify({ editor: model, siteId: '@ViewBag.siteId' }), 
         success: function() { 
          alert('تغییرات مورد نظر با موفقیت اعمال شد.'); 
          //window.parent.document.location.replace('@Url.Action("SiteIndex", "Editor")?' + parametrs); 
         }, 
        error: function() { 
         alert('متاسفانه خطایی در سیستم رخ داد،دوباره تلاش کنید.'); 
        } 
       }); 
      }); 

这是正确的

1

您不能JSON序列化包含循环引用的对象层次结构。这仅仅是JSON格式不支持的。您应该使用视图模型并打破对象中存在的循环依赖关系。

+0

请给我解释一下 –

相关问题