如何解决:无法将类型 'System.Decimal' 的对象转换为类型 'System.String'

How To Solve :Unable to cast object of type 'System.Decimal' to type 'System.String'

我创建了一个 Class 具有两个 Decimal 类型的属性,之后我创建了控制器并使用 Visual Studio 自动查看......但是当我输入 Create 的值时我收到此错误的表格: 无法将类型 'System.Decimal' 的对象转换为类型 'System.String'。

这里是模型中我的 Class 变量的小数部分:

[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>

删除 StringLength 属性。