I've got a form inside an <asp:Content>
block that is being submitted to a controller. For one of the controls, I need to get some information from it directly that won't happen automatically by calling UpdateModel()
.
However, in the Request.Form
dictionary, the control's id is of the mangled form ctl00$ContentPlaceHolder${name}
. Given that I'm in the controller, and know nothing about the view at this point, what is the proper way of accessing the control's data?
Here is what the view (.aspx) looks like (removed extraneous code):
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" AutoEventWireup="true"
CodeBehind="...." Inherits="...." %>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder" runat="server">
<form id="form1" action="..." method="post">
<FCKeditorV2:FCKeditor ID="AuthorBio" runat="server" Height="250"/>
<input type="submit" value="Save" />
</form>
</asp:Content>
The control named AuthorBio
shows up in the controller in the Form.Request
dictionary as ctl00$ContentPlaceHolder$AuthorBio$
The reason I'm trying to use the 3rd-party control with "runat-server" is because I need to set the editor's Value as follows:
AuthorBio.Value = HttpUtility.HtmlDecode(ViewData.Model.Bio);
Trying to do this in the .aspx file in the FCKeditorV2 tag doesn't work. (Or maybe I'm missing something there too)
Ok, so the key is to use the JavaScript version of the editor rather than the wrapped control. There was also a handy comment that I'm going to include here to accompany the accepted answer:
you should use the javascript version of the FCKEditor control not the .NET custom control as the .NET custom control was built on the WebForms paradigm. The JS version should have a hidden field for the value of the Html which you can access in your controller using Request["FieldName"]