简体   繁体   中英

Unable to cast object of type 'System.Decimal' to type 'System.String'. after creating the EDIT View

Getting this error executing the EDIT View during the [HttpPost] or SAVE action.

This is the first time Saving Changes to the Edited Data and the form does a dump giving the above error.

Changed a field from decimal to string and thought that was the problem but thinking now it is NOT. Made the change in the database - then edited the Model from:

    public Nullable<decimal> F_RENO { get; set; }

to:

    public string F_RENO { get; set; }

and in the Metadata I have:

    [Display(Name = "R.E. NO.")]
    [StringLength(3)]
    public string F_RENO;

Also edited the MTSMODEL.EDMX for the table/field from decimal - to string

Is there somewhere else I missed? Should the table be remove from the .EDMX then re-added?

Everything seemed to work until I tried to Edit the record.

The problem was in the Metadata for this Model. My Model nameed mts_aggrtest when completely removed the Models.Metadata.mts_aggrtestMetadata the EDIT view was able to save Edits. In one of the 90+ fields there probable is [StringLength(xx)] on a numeric field or something similar. Bad Programming not enough testing.

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