1

I try to render cyrillic word "име" instead of the name of the column(FirstName) in the table from the DataBase but instead i receive some strange symbols "Èìå". I have a <globalization fileEncoding="utf-8" /> in my webconfig and also I've checked the files containing the code and they are all saved as UTF-8.

I am pretty sure the problem is caused by something in ModelRS.edmx or the files contained in this hierarchy. Here are two screenshots that provide more of the code.

enter image description here

enter image description here

Should I just hardcode "Име" in the HTML as I tried and works fine but it feels like bad practice and this is a project I'm showing to a exam judges?

My html block (see also the screenshot for comperhensive info):

@using PagedList.Mvc;
@model PagedList.IPagedList<Rating_System.Models.tblTeacher>

@Html.DisplayNameFor(model => model.First().FirstName)  
// I have .First() because the web page has pagination 

My controller:

public class TeachersController : Controller
    {
        private RSEntities db = new RSEntities();

        // GET: Teachers
        public ActionResult Index(int page = 1, int pageSize = 8)
        {
            List<tblTeacher> listTeachers = db.tblTeachers.ToList();
            PagedList<tblTeacher> model = new PagedList<tblTeacher>(listTeachers, page, pageSize);
            //return View(db.tblTeachers.ToList()); 
            return View(model);
        }
    }

My "Model":

 public partial class tblTeacher
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public tblTeacher()
    {
        this.tblRatings = new HashSet<tblRating>();
        this.tblTeachersDisciplines = new HashSet<tblTeachersDiscipline>();
    }

    public int ID { get; set; }

    [Required]
    [Display(Name = "Име:")]
    [StringLength(50)]
    public string FirstName { get; set; }
}
Georgi93
  • 47
  • 1
  • 8
  • I have paged a couple of my views and didn't need to use `.First()`.. what happens when that is taken out? I see you had the data annotation on the model to be set to what you wanted. That doesn't work? – Grizzly Oct 03 '16 at 19:40
  • When i remove .First() Visual Studio does not recognise FirstName And i commented the first model because i use pagination and the second one is required. I cannot have two models, thoguh – Georgi93 Oct 03 '16 at 19:44
  • I have had that happen to me before as well.. Just type it in manually. Intellisense doesn't recognize it. `@Html.DisplayNameFor(model => model.FirstName)` – Grizzly Oct 03 '16 at 19:47
  • In your controller, do you have `using PagedList` or is that only in your view? – Grizzly Oct 03 '16 at 19:51
  • yes I have using PagedList; – Georgi93 Oct 03 '16 at 19:54
  • Okay, I will post a different way to page with that using statement, but first is your `Display` data annotation working correctly, or no? – Grizzly Oct 03 '16 at 19:57
  • no, it keeps showing some strange symbols. Only way i can think of now is is to hard code what i want – Georgi93 Oct 03 '16 at 21:01
  • Did you check using Html.Raw? – Hackerman Oct 03 '16 at 22:21

3 Answers3

0

Can sound like a pretty strange thing, but you need to check that your .cs file containing model is saved exactly in utf-8 encoding. I.e. try to open this file in some editor like notepad++ and save exactly in utf-8.

We are using Cyrillic Display("Name"...) a lot, so it shouldn't be a core issue.

MagisterCrazy
  • 225
  • 1
  • 10
0

AFAIK, Visual Studio has option to save a file with different encoding. Open your CS file which contains model class, select File => Save As => Save with Encoding and choose "UTF-8 with signature" (or other encoding you've needed) on Advanced Save Options.

If solutions above still doesn't work, open your Layout.cshtml file which contains base HTML tag for view pages, then use both lang attribute and meta tag:

<html lang="ru">

<meta charset="UTF-8">

This will declare entire view page containing the layout page as Russian with UTF-8 encoding, thus Cyrillic characters should rendered properly as given by Display attribute.

For Intellisense problem that doesn't recognize your model class name, go to Tools => Options => Text Editor => C# => Intellisense, and check if 2 conditions below applied:

  1. "Show completion list after a character is typed" has checked.

  2. "Commited by typing the following characters" text box contains {}[]().,:;+-*/%&|^!~=<>?@#'"\.

Other suggestions welcome.

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
0

The solution was to encode tblTeachers (this is my model),as some of you suggested, to UTF-8 and save it that way. Before that I was only opening the Controller and HTML pages with the notepad ++ and they were all UTF-8, but I forgot to check the model.

Georgi93
  • 47
  • 1
  • 8