开发者

help me ! MVC and AJAX toolkit Editor in ASP.NET

I have view to use Ajax toolkit editor control.

View 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();
    }

When I added a product, just slogan was added, content was null.

I dont understand and ho开发者_如何学Gow to repair it. Help me, please! Thanks so much!


It does not work this way. You are mixing ASP.NET WebForms with MVC. ID="content" only sets the server-side ID of the Editor control. Controller parameters however are mapped by form field names and in your case the name of the corresponding textarea is generated automatically. I'm not aware of any way you could normally change the name of a control rendered by ASP.NET. You can, however try the following:

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

Put this at the bottom of your view. It might just work.

Keep in mind that even if it works, the above is a dirty hack. The right approach in an MVC project would be to initialize the Editor control using just client scripting. This is not always easy but doable. For reference, try looking at the source of this page:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜