![]() Here’s an example:īased on my experience, I’d suggest that this workaround is the best compromise you can get. There are a few workarounds to this problem.įirst and foremost, you can use the UIHint data annotation to decorate the read-only property. For some reason, this information is just ignored by default templates. The ReadOnly attribute is properly recognized by the metadata provider, and related information is stored in the metadata available for the model. The metadata provider reads information about a given class and exposes that to ASP.NET MVC templated editors. But there’s more to it.ĭata annotations are connected to ASP.NET MVC through the services of a special component known as the metadata provider. You would likely expect that a member with such an annotation be not editable in the form and rendered using the display template for the data type. The Id property of the Article is rendered with a textbox, albeit decorated with the ReadOnly data annotation attribute. A revisited HTML editor formatted as a table. For example, the IsRequired property checks the existence of the Required attribute on the property and enables the “*” symbol close to the input field. Here’s some sample code for an editor template that renders properties within a multi-column HTML table.Ī bit of reflection allows us to determine information about public properties and their metadata. You just need to write a file named object.cshtml and place it under the folder Views//EditorTemplates. ![]() Make the new template handle property the ReadOnly attributeĭisplay and editor helpers come with their own default template, but it is relatively easy to define a custom template. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |