2011-06-13 69 views
0

我有意使用Ajax工具包編輯器控制。幫助我! MVC和AJAX工具包編輯於ASP.NET

查看CreateProduct

<fieldset> 
      <legend>Product information</legend> 
      <table align="center"> 
       <tr> 
        <td><label for="slogan">Slogan:</label></td>     
        <td><%= Html.TextBox("slogan")%></td> 
       </tr> 
       <tr> 
        <td><label for="content">Content :</label></td> 
        <td> 
         <asp:ScriptManager ID="ScriptManager1" runat="server"> 
         </asp:ScriptManager> 

         <cc1:Editor ID="content" runat="server" Height="300px" /> 
        </td> 
       </tr> 
      </table> 
    </fieldset> 

ProductController的:

 public ActionResult CreateProduct(string slogan, string content) 
    { 
     ProductDataContext data = new ProductDataContext(); 
     PRODUCT p = new PRODUCT(); 

     p.SLOGAN = slogan; 
     p.CONTENT = content; 

     data.AddProduct(p); 
     data.SubmitChanges(); 

     return View(); 
    } 

當我加了一個產品,只是口號加入,內容爲空。

我不明白,以及如何修復它。 請幫幫我! 非常感謝!

回答

1

它不這樣工作。您正在將ASP.NET WebForms與MVC混合使用。 ID =「content」僅設置編輯器控件的服務器端ID。然而,控制器參數通過表單字段名稱映射,在您的情況下,相應的textarea的名稱會自動生成。我不知道有什麼方法可以正常更改ASP.NET呈現的控件的名稱。您可以嘗試以下操作:

<script type="text/javascript"> 
document.getElementById('<%= content.ClientID =>').name = 'content'; 
</script> 

將此放在視圖的底部。它可能只是工作。

請記住,即使它工作,上述是一個骯髒的黑客攻擊。 MVC項目中的正確方法是使用客戶端腳本初始化Editor控件。這並不總是容易但可行。僅供參考,請看這頁的來源:

http://www.asp.net/ajax/ajaxcontroltoolkit/samples/htmleditor/OtherSamples/ClientSide.htm

+0

謝謝你的任何方式! – 2011-06-18 07:41:13