2013-09-22 17 views
1

嗨我已將tinyMCE文本編輯器添加到我的項目。但是現在我的表單不會提交,也不會收到任何錯誤信息或任何內容。我在這裏做錯了什麼?安裝後提交不發送請求TinyMCE

我的.cshtml代碼

@{ 
Layout = "~/Views/_Layout.cshtml"; //Got a link to the tinyMCE file 

var con = DatabaseConnection.createConnection(); 
string subject = ""; 
string content = ""; 
string signed = ""; 
string message_error = ""; 
int subfolderTo = 0; 
int id = 0; 
bool error = false; 

if(Request["btn"] == "Save entry") 
{ 
    subject = Request["subject"]; 
    content = Request["content"]; 
    signed = Request["signed"]; 

    if(Request.QueryString["Chapter"] != null) 
    { 
     subfolderTo = Convert.ToInt32(Request.QueryString["Chapter"]); 
    } 

    if(subfolderTo == 0) 
    { 
     try 
     { 
      id = Subjects.Create(con, SessionHandler.WhoIsLoggedIn._id, subject, content, signed); 
      Response.Redirect("~/Pages/Chapters/Read.cshtml?Chapter=" + id); 
     } 
     catch 
     { 
      error = true; 
      message_error = "A monkey ran away with the text before we could save it, we are very sorry. Please try again."; 
     } 
    } 
    else 
    { 
     try 
     { 
      id = Subjects.Create(con, SessionHandler.WhoIsLoggedIn._id, subject, content, signed, subfolderTo); 
      Response.Redirect("~/Pages/Chapters/Read.cshtml?Chapter=" + id); 
     } 
     catch 
     { 
      error = true; 
      message_error = "A monkey ran away with the text before we could save it, we are very sorry. Please try again."; 
     } 
    } 
} 

} 


@section head{ 
<script type="text/javascript"> 
    tinymce.init({ 
     selector: "textarea", 
     theme: "modern", 
     plugins: [ 
      "advlist autolink lists link image charmap print preview hr anchor pagebreak", 
      "searchreplace wordcount visualblocks visualchars code fullscreen", 
      "insertdatetime media nonbreaking save table contextmenu directionality", 
      "emoticons template paste textcolor moxiemanager" 
     ], 
     toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image", 
     toolbar2: "print preview media | forecolor backcolor emoticons", 
     image_advtab: true, 
     templates: [ 
      { title: 'Test template 1', content: 'Test 1' }, 
      { title: 'Test template 2', content: 'Test 2' } 
     ] 
    }); 
</script> 

} 


<div> 
<h1> 
    Write new entry 
</h1> 
<form action="" method="post"> 
    <p class="Error_Message">@message_error</p> 
    <table> 
     <tr> 
      <td> 
       <p> 
        <input type="text" name="subject" placeholder="Subject" value="@subject" required="required"/> 
       </p> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <p> 
        <textarea name="content" placeholder="Content" required="required"></textarea> // used to be a <input type="text" ... /> before 
       </p> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <p> 
        <input type="text" name="signed" placeholder="In-time signed name" value="@signed" required="required" /> 
       </p> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <input type="submit" value="Save entry" name="btn" /> 
      </td> 
     </tr> 
    </table> 
</form> 
</div> 

回答

0

我不知道爲什麼,但添加

content = Request.Unvalidated("content"); 

and changing

<textarea name="content" placeholder="Content" required="required"></textarea> 

<textarea name="content" ></textarea> 

,現在它的工作原理。如果有答案爲什麼,我想知道^^

1

如果你想發佈的HTML,你必須使用Request.Unvalidated()引用textarea的內容:

content = Request.Unvalidated("content"); 
+0

嘗試了您的解決方案,但'submit'仍然不會創建對頁面的請求。 –