简体   繁体   中英

Model Binding HTML control to Model Property with a different name

I have an HTML input control on one of my views that is called for example 'BodyInput'. When I post the form I am checking if the ModelState is valid or not. The other few input controls on my view validate fine, as the name of the properties in my model are exactly the same as the name of the HTML controls, but the name of my property for the 'BodyInput' control to map to, is 'Body'.

Lets say I can't change the name of either the property in my model, or the Html input control - can I use data annotations (or anything) to map/associate the property and control for model binding?

Found a solution in another question as pointed out by user ipr101.

Bind formValue to property of different name, ASP.NET MVC

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