views:

89

answers:

1

I am trying to add an ajax form to my application. The problem is that I want to pass my input as gb2312 encoded. However I wasn't able to do

new {accept-charset="gb2312"}

as msdn suggested. I guess it's because the "-" in "accept-charset" breaks the CSharp variable naming rule. I tried to add an "@" in front of "accept-charset" but it didn't work either. Does anyone know what trick should I apply to solve this problem?

+2  A: 

MSDN is wrong: accept-charset is not a valid identifier.

Try using the BeginForm overload that takes an IDictionary htmlAttributes instead of an Object.

Example:

<% var attributes = new Dictionary<string, Object>();
   attributes.Add("accept-charset","gb2312");
   using (Ajax.BeginForm( "action", null, new AjaxOptions { ... }, attributes ))
   {
 %>

<% } %>
Amnon
This is the way to do it. I was thinking you needed to set the request header, but it's much simpler to just set the form attribute. Doh! Hope you don't mind that I added an example.
tvanfosson
It indeed worked, but has to be with one slight modification. var attributes has to be of type Dictionary<string, object> instead of Dictionary<string, string> otherwise the generated html is incorrect.
Wei Ma