简体   繁体   中英

Modify the special characters in asp.net mvc

I have a problem with c# and html code with 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>
    <!-- partie calendrier-->
     <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>

I get this result :

错误

In the line Tâche: développement the result is Tâche: d&amp;#233;veloppement . So the character â is accepted but the é is not.

What is the reason of this error? How can I fix it?

The important line here is

title: "Tâche: @Model.Get_List_Tache()[i].Tache_description"

The "Tâche: " part is just plain text, whereas your "développement" is dynamic. The dynamic part is probably escaped/encoded, either in your data storage or by the framework before sending it to the client.

For a solution, see the question and answers at

One of your options is to use @Html.Raw( ... dynamic text ... ) , but be careful with it, it could also write characters that will make your javascript invalid (Imagine your dynamic string contains a ; or a " ).

Razor is HTML-encoding your Javascript output.

You need to prevent that by calling Html.Raw() .
You also need to Javascript-escape it to prevent XSS holes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM