1

tinyMCEエディターのインスタンスを含むフォームをAJAXを使用してアクションメソッドに投稿しようとしています。私の見解:

<script src="@Url.Content("~/Scripts/tinymce/tiny_mce.js")" type="text/javascript"></script>

<div>
    <fieldset>
       @using (Html.BeginForm("SubmitNewTRForm", "LaboratoriesOrdersGrid", FormMethod.Post,
            new {enctype = "multipart/form-data", @id = "newTrUploadForm" }))
            {
                <div  style="overflow: hidden;width: 763px; height:312px;  border: black solid thin;">
                      @Html.TextAreaFor(model => model.TestSummary, new {@class="TestSummaryEditor"})
                </div>
             }

    </fieldset>
</div>

同じビューで、エディターをインスタンス化します。

    $(document).ready(function () {
        tinyMCE.init({
            directionality: "rtl",
            width: "760",
            height: "300",
            language: 'fa',
            // General options
            mode: "textareas",
            theme: "advanced",
            plugins: "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
            // Theme options
            theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,|,sub,sup,|,charmap,iespell,advhr,|,print,|,fullscreen",
            theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,cleanup,|,insertdate,inserttime,preview,|,forecolor,backcolor,|,insertlayer,moveforward,movebackward,absolute,|,blockquote,pagebreak,|,insertfile,insertimage,|,visualchars,nonbreaking,template",
            theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,ltr,rtl,|,cite,abbr,acronym,del,ins,attribs",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            theme_advanced_resizing: true,
            // Skin options
            skin: "o2k7",
            skin_variant: "silver",
            add_form_submit_trigger: false,
            // Example content CSS (should be your site CSS)
            content_css: "css/example.css",
            // Drop lists for link/image/media/template dialogs
            template_external_list_url: "js/template_list.js",
            external_link_list_url: "js/link_list.js",
            external_image_list_url: "js/image_list.js",
            media_external_list_url: "js/media_list.js",
            // Replace values for the template plugin
            template_replace_values: {
                username: "Some User",
                staffid: "991234"
            }
        });

    });

私のAJAX呼び出しと:

        $("form").live('submit', function (e) {
            tinyMCE.triggerSave(true, true);
            e.preventDefault();

    var form = $("#newTrUploadForm");
            if (form.valid()) {
                    $.ajax({
                        url: '@Url.Action("SubmitNewTRForm")',
                        data: form.serialize(),
                        type: 'POST',
                        error: function (xhr, textStatus, exceptionThrown) {
                            $("#errorDIV").html(xhr.responseText);
                        },
                        success: function (data) {
                            if (data.success) {

                            }
                            else {

                            }
                        }
                    });
                }
        });

そして、私のAJAX呼び出しは、tinyMCEエディターがフォーム上にあるときは常にエラーを返し、tinyMCEを削除すると問題が解決しますが、なぜこれが発生するのですか?私はこの問題がすでに数回SOで対処されていることを知っていますが、提案されたすべての解決策を試しましたが、どれもうまくいかないようです。さらに、それらの解決策はやや時代遅れです。AJAX呼び出しでのシリアル化中に、次のエラーが発生します。

[MissingMethodException: No parameterless constructor defined for this object.]

何か案は?

4

2 に答える 2

1

私が投稿したエラーと tinyMCE の問題はまったく無関係です。tinyMCEの問題は、ボタンクリックのデフォルトアクションを防止した後にコンテンツを保存することで修正され、基本的にAJAX呼び出しを次のように変更しました。

   $("form").live('submit', function (e) {
        tinyMCE.triggerSave(true, true);
        e.preventDefault();

に:

   $("form").live('submit', function (e) {
       e.preventDefault();
       tinyMCE.triggerSave(true, true);

フォームは適切にシリアル化され、編集者のコンテンツは問題なくアクションに送信されました。

この質問とはまったく関係ありませんが、投稿されたエラーは、モデル プロパティのタイプを as に設定SelectListし、フォームを投稿したことが原因でしたSelectListItem

于 2012-12-18T13:52:13.783 に答える
0

エラーは、コントローラーアクションでバインドしようとしているモデルに次のようなコンストラクターが必要であることを示しています

public yourModel
{
    public yourModel()
    {
        //your logic here
    }
}

また、そもそも投稿するための「フォーム」がビューにあるようには見えません。複数のエラーが重なり合っており、パラメーターのないコンストラクターは最初のエラーにすぎないと感じています。

于 2012-12-18T13:00:58.293 に答える