Changing the special characters in ASP.NET MVC

I'm facing an issue with c# and html code that involves special French characters :

<html>
<head>
    <link rel="stylesheet" href="~/Content/jquery.treeview.css" />
    <script src="~/Content/jquery.cookie.js" type="text/javascript"></script>
    <script src="~/Content/jquery.treeview.js" type="text/javascript"></script>
    <script type="text/javascript" src="~/Content/demo.js"></script>
    <!-- calendrier section-->
     <link rel="stylesheet" href="~/Scripts/Calendar/theme.css" />
    <link href="~/Scripts/Calendar/fullcalendar.css" rel="stylesheet" />
    <link href="~/Scripts/Calendar/fullcalendar.print.css" rel="stylesheet" media="print" />
    <script src="~/Scripts/Calendar/fullcalendar.min.js"></script>
      <style>
        body
        {
            background-color:#eee;
        }

        #tree {
            background-color:#eee;
        }
        .affaire {
            color:black;
                font-size: 16px;
        }
        .tache {
            color:black;
                font-size: 12px;
        }
         .projet {
            color:blue;
                font-size: 20px;
        }
           .sequence {
            color:blue;
                font-size: 16px;
        }
           #calendar {
        width: 900px;
        margin: 0 auto;

        }
          p {
             color:white;
                font-size: 12px;
          }
          #status
{
   position:absolute;
   left:60%;

}
    </style>

    <style>
    input {
    border: 1px solid #e2e2e2;
    background: #fff;
    color: #333;
    font-size: 1.2em;
    margin: 5px 0 6px 0;
    padding: 5px;
    width: 300px;
    }
        a {
            font-size:14px;
        }

        </style>

    <script>

        $(document).ready(function () {
            var date = new Date();
            var d = date.getDate();
            var m = date.getMonth();
            var y = date.getFullYear();
            var tab = [];
            var d1 = [];
            var m1 = [];
            var y1 = [];
            var d2 = [];
            var m2 = [];
            var y2 = [];
            var colors = [];

             @for(int i =0; i< @Model.Get_List_Tache().Count;i++){

                 @: d1.push(@Model.Get_List_Tache()[i].Begin_date.Day);
                             @: m1.push(@Model.Get_List_Tache()[i].Begin_date.Month);
                             @: y1.push(@Model.Get_List_Tache()[i].Begin_date.Year);
                             @: d2.push(@Model.Get_List_Tache()[i].End_date.Day);
                             @: m2.push(@Model.Get_List_Tache()[i].End_date.Month);
                             @: y2.push(@Model.Get_List_Tache()[i].End_date.Year);
                         }
            d1.reverse();
            m1.reverse();
            y1.reverse();
            d2.reverse();
            m2.reverse();
            y2.reverse();
            @for(int i =0; i< @Model.Get_List_Tache().Count;i++){
            @:var e = { title: "Tâche: @Model.Get_List_Tache()[i].Tache_description", start: new Date(y1.pop(), m1.pop() - 1, d1.pop(), 08, 00), end: new Date(y2.pop(), m2.pop() - 1, d2.pop(), 18, 00), allDay: true, color: "@Model.GetColors()[i]", };
                        @: tab.push(e);
        }
            $('#calendar').fullCalendar({
                theme: true,
                header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' },
                editable: true,
                events: tab
            });

        });


</script>


</head>
    <body>

     <table > <tr><td style="background-color:darkcyan; width:30%;"> <p>Tâche en cours</p></td><td style="background-color:black;width:30%"> <p>Tâche terminée</p></td><td style="background-color:darkred;width:30%"> <p>Tâche en urgence</p></td></tr>
           </table>
    <br />
        <br />

        <table><tr><td style="" >

 </td> <td > 
        <div id='calendar'></div>
</td>

            </tr>
            </table>

    </body>
</html>

After implementing the code, I encountered this problem:

In the line Tâche: développement, instead of getting Tâche: développement, I received

Tâche: d&amp;#233;veloppement
. It seems like the character â is displayed correctly, but é is not.

Could you please help me understand the cause of this error? How can it be resolved?

Answer №1

In this context, the key point to note is

title: "Task: @Model.Get_List_Tache()[i].Tache_description"

The "Task: " section is static text, while the "development" part is dynamically generated. It's likely that the dynamic portion is encoded or escaped, either in your database or by the framework prior to its transmission to the client.

To find a solution, check out the discussions on

  • HTML encode decode c# MVC4
  • ASP MVC Razor encode special characters in input placeholder

One possible approach is to utilize

@Html.Raw( ... dynamic text ... )
, but proceed with caution as it may inadvertently introduce characters that could render your JavaScript code invalid (Consider scenarios where your dynamic string contains a ; or a ").

Answer №2

Razor is encoding your JavaScript output using HTML.

To stop this, you should use Html.Raw().
Don't forget to escape the JavaScript to avoid XSS vulnerabilities.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for adjusting the size of a v-text-field within a d-flex layout in Vue

I'm a beginner with Vue and I have encountered an issue with two v-text-field elements in a flexbox. They are currently taking up the entire available space on a line when displayed side by side. However, I would like to make them smaller. Despite try ...

Is there a way to intercept the call to a specific property on an interface using Rhino Mocks, while still allowing all other calls to flow through to the default implementation?

In need of a solution with my interface IComplex containing numerous methods and properties, I am looking to generate a "mock" that will have the "Config" property return an object of my choosing. This mock should redirect all other calls to a genuine inst ...

Exploring the possibilities of color manipulation with .NET ColorMatrix

Is there a way to adjust the pixels of an image by setting them to white if the red channel value is less than 165, and then setting all remaining pixels to black? Would it be possible to achieve this using ColorMatrix? ...

Trouble with the Ngx-Captcha feature

I am currently utilizing https://www.npmjs.com/package/ngx-captcha/v/11.0.0. <ngx-recaptcha2 #captchaElem [siteKey]="'6Leh1ZIjAAAAAG8g0BuncTRT-VMjh3Y7HblZ9XSZ'" (success)="handleSuccess($event)" [useGlobalDomain]="fals ...

Unable to locate the iframe in the test scenario

I encountered this particular test case: Select Frame id=coach_frame63454108.cf1 Wait Until Element Is Visible ${ap.gui.header.appname} Page Should Contain Element ${ap.gui.header.appname} Page Should Contain Element ${ap.gui.hea ...

Place the div directly beside the input field on the right side

I am attempting to align a div directly beside the text being entered in a text input field. It seems logical to me that this could be achieved by measuring the length of the input value and positioning the div accordingly. However, the issue I am facing i ...

Numerous pop-up windows displaying a variety of distinct content in each one

While working on a website, I came across a helpful jQuery pop-up function that I found on Stack Overflow. The original post can be found here. I am trying to customize each pop-up box so they contain different content from the .pop1 and .pop2 divs (parag ...

Relocating the output of JavaScript to a different location

I'm currently facing an issue with transferring my JavaScript output (start) from the black box to the grey box. I am unsure about what needs to be included in the functions (moveRight and moveLeft) for the transition to occur smoothly. Even after re ...

Having trouble getting the on:dblclick event to trigger on a row within a list using S

I am currently using Sveltestrap and I am in need of a double click handler for a row: <ListGroupItem on:dblclick={handler(params)}> <Row> <Col><Icon name=........</Col> ... </Row> </ListGroupItem> Int ...

Checkbox selection and display: Check the box to reveal its value in a div, along with a close button for

While following a tutorial, I came across a scenario where multiple checkboxes are involved. Upon selecting the checkbox and clicking on the "get selected value" button, the value of the selected checkboxes is alerted. However, I would like to make a mod ...

What are the steps to display JSON data within an HTML div?

Struggling to display this JSON data within an HTML div [{ "botten": ["Crispy", "thin"] }, ] The HTML document's div has the class name box1_data. Below is my script: var crustInfo = document.getElementsByClassName("box1_data"); $.getJSON(' ...

modification of the tooltip's background shade on Google Maps

Currently, I am using Google Chart to display data for different countries. When hovering over these countries, a tooltip is displayed which fetches data from the backend. However, I would like to customize the background color of this tooltip as it is cur ...

Overlap in Bootstrap 4 Sections

I'm facing an issue with two sections on my website. They are properly separated until a certain size, https://i.sstatic.net/e52t2.png, but when the size is reduced, they start to overlap https://i.sstatic.net/aMtHr.png. Below is a snippet of my code: ...

identify when the React component has reached the bottom of the element by reading the

Is there a way to access the scroll handler's event without being able to access offsetTop, scrollTop, etc? class App extends React.Component { handleScroll = e => { console.log(e.target.scrollTop); }; componentDidMo ...

Implementing JSON data binding for webgrid in ASP.net MVC4

I am struggling to populate a webgrid with Datatable values using Json. I have implemented a DropDownlist to select a person's name, and based on that selection, I want to display the corresponding data in the webgrid. However, my current code does no ...

Does anyone know if it's achievable to include a background position within the img /asp:image tag?

Currently, I am endeavoring to enhance the loading speed of my webpage. The initial approach I decided to pursue is base64 conversion. On my homepage, there are a total of 18 small images that need to be loaded. Since base64 encoding increases image size ...

Unable to toggle visibility of image

I integrated the jquery.smoothZoom.min.js plugin for zooming and panning images successfully in my project. Now, I am attempting to create a carousel functionality (<,>.i.e. corousal) to use it with multiple images. However, when I added the correspo ...

What is the best way to style a select element to achieve this appearance?

https://i.sstatic.net/4yGqf.png Currently working on converting a .psd file to html/css and encountering difficulty with a unique looking select element. Struggling to find a suitable example online for reference. Wondering if this design element is indee ...

Is there a way to verify whether all elements (text, email, number, and radio) within a specific div have been selected or filled

Is there a way to activate the submit button on a form only when all inputs are checked or not empty? I've come across various snippets on Google and SO that achieve something similar, but they only work for a specific type of input, not taking into ...

I don't understand why my BeautifulSoup code is throwing an attribute error even though the variable it's referring to is assigned a value

Currently, I am working with Python 3.9.1 along with selenium and BeautifulSoup to develop my first web scraper targeting Tesco's website. This is essentially a mini project that serves the purpose of helping me learn. However, upon running the code p ...