简体   繁体   中英

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

I Have Created a Class With Two Properties Of Type Decimal And after that i Created The Controller And View Automatically By Using Visual Studio .....But When I Entered The Values Of Create Form I Got This Error: Unable to cast object of type 'System.Decimal' to type 'System.String'.

Here The Part Of Decimals Variable In My Class in Models:

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

And Here Is The Part Of View Code In Create File(Only Decimal Part):

    <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属性。

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