I have an ASP.NET MVC application. In one of the forms I am having problems with the coding of character Ñ. It is shown as below:
Ñ
This form have several objects such as TextBoxFor and select, among others. Initially when page is loaded for first time Ñ character is show correctly in all the html objects (TextBoxFor, Select among others). Once I have filled in all the fields I click on a save button in order to save values into database. Then page is reloaded and it keeps all the fields filled in (they are not cleared).
Once page is reloaded the Ñ character is shown as:
Ñ
in the html Select object below:
<select class="form-control" id="street" name="street"></select>
but in the other objects such as TextBoxFor is being shown correctly as Ñ :
@Html.TextBoxFor(model => model.DepartmentName, new { @class = "input-xmediumlarge" }, (bool)( !ViewBag.ReadOnly), true)
Html Select object is populated from a query to database. While user types characters in it, a search is done on the fly (using JQuery) and items containing that string are being shown to select. Items shown on the fly which contains Ñ character are displayed correctly. The problem is once values are saved and page reloaded. Ñ character is shown incorrectly in the html select object. It only happens in select object. In all other objects Ñ character is correctly displayed.
I have indicated below statements in the head section of the page:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
Also, the cshtml view is saved as UTF-8. I have checked it by using Notepad++ by following these steps: Open the file in Notepad. Click 'Save As...'. In the 'Encoding:' combo box I see the current file format UTF-8.
So what am I doing wrong?
UPDATED: I have debugged and inspected the generated source code by internet browser (chrome, firefox and so on) and I can see the problem is when setting de html select value using jquery as below:
$('#street').val('@Model.street');
Above line is interpreted as below by the internet browser:
$('#street').val('PEÑALBES');
so in the html select object is displayed as:
PEÑALBES
instead of PEÑALBES.