my DB model has the column name with "_" in the field name. is there a way to dislay these values in Camel Case when displaying in the form? like "BusinessName"
i am using asp.net MVC3 with Razor
@Html.LabelFor(model => model.business_name)
Could you not just use the DisplayAttribute?
You need a new metadataprovider which can inherit from the default one like this:
using System;
using System.Web.Mvc;
using System.Collections.Generic;
public class MyMetadataProvider : DataAnnotationsModelMetadataProvider
{
protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
{
var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
if (metadata.DisplayName == null)
metadata.DisplayName = GetDisplayNameFromDBName(propertyName);
return metadata;
}
private string GetDisplayNameFromDBName(string propertyName)
{
return ...;
}
}
Register it in global.asax like this:
ModelMetadataProviders.Current = new MyMetadataProvider();
You just need to provide the implementation of GetDisplayNameFromDBName to provide the correct display name given the property name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With