Как решить: невозможно привести объект типа 'System.Decimal' к типу 'System.String' - PullRequest
0 голосов
/ 29 марта 2019

Я создал класс с двумя свойствами типа Decimal и после этого я создал контроллер и просмотр автоматически с помощью Visual Studio ..... Но когда я ввел значения формы Create, я получил эту ошибку: Невозможно привестиобъект типа 'System.Decimal' для типа 'System.String'.

Здесь переменная часть десятичных чисел в моем классе в моделях:

[Display(Name = "رسوم الدورة")]
[StringLength(100, ErrorMessage = "العنوان طويل")]
[DisplayFormat(DataFormatString = "{0:F2}", ApplyFormatInEditMode = true)]
public decimal CourseFees { get; set; }

[Display(Name = "الشهادة")]
public Certificate Certificate { get; set; }

[Display(Name = "رسوم الشهادة")]
[StringLength(100, ErrorMessage = "العنوان طويل")]
[DisplayFormat(DataFormatString = "{0:F2}", ApplyFormatInEditMode = true)]
public decimal CertificateCost { get; set; }

И вот часть представленияКод в файле создания (только десятичная часть):

    <div class="form-group">
        <label asp-for="CourseFees" class="control-label"></label>
        <input asp-for="CourseFees" class="form-control" />
        <span asp-validation-for="CourseFees" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="Certificate" class="control-label"></label>
        <select asp-for="Certificate" asp-items="Html.GetEnumSelectList<Certificate>()" class="form-control"></select>
        <span asp-validation-for="Certificate" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="CertificateCost" class="control-label"></label>
        <input asp-for="CertificateCost" class="form-control" />
        <span asp-validation-for="CertificateCost" class="text-danger"></span>
    </div>

1 Ответ

1 голос
/ 29 марта 2019

Удалить атрибут StringLength.

...