开发者

How to send html text to ASP.NET Generic Handler?

I have a WYSIWYG editor on one of my forms and I want to send the contents of the editor to an ASP.NET generic handler for processing via an Ajax call.

I am having a little bit of trouble parsing the html received.

Client Side:

$(function(){
  开发者_开发技巧 $('.send').bind('click', function(event){

       var message = $('#TxtMessage').htmlarea('toHtmlString');
       message = escape(message);

       $.get('/Handlers/EmailHandler', { message: message }, function(data){

           if( data != null || data != '' )
           {
               var success = eval(data);

               if( success ){
                   alert('Email sent');
               }
           }
       });

    });
});

Server side:

public class EmailHandler : IHttpHandler, IRequiresSessionState
{
   public void ProcessRequest(HttpContext context)
   {
       context.Response.ContentType = "text/plain";
       string message = (string.IsNullOrEmpty(context.Request.Params["message"]) ? string.Empty : context.Request.Params["message"].ToString());

       message = context.Server.HtmlDecode(message);

       //do whatever...
    }
}

So the problem is that even when I call Server.HtmlDecode(string) the message is garbled.

Any ideas on how to fix that?


The right way of parsing string sent to the server via JavaScript by using escape() is to use HttpServerUtility.UrlDecode();

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜