John Churchley
John Churchley

Reputation: 444

Concatenate string to Display Culture Value MVC 4+

Hi I've followed the following post in order to localize labels for a form.

http://afana.me/post/aspnet-mvc-internationalization.aspx

I works perfectly but I'm trying to find a way to concatenate ":" on to the display value (i.e. Address:)?

View:

<div class="col-sm-5">
 @Html.LabelFor(model => model.Address)
</div>

Model:

 [Required]
 [Display(Name = "Address", ResourceType = typeof(Resources.Resources))]
 public string Name { get; set; }

key in resx file

Name :Address
Value:Address

My attempts are:

Change the model

[Display(Name = "Address" + ":", ResourceType = typeof(Resources.Resources))]

Change the view

@Html.LabelFor(model => model.Address, Name + ":")

Anyone with any ideas if it's possible? Is there away to get the Name property and manipulate it in the view?

https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute%28v=vs.110%29.aspx

Upvotes: 0

Views: 458

Answers (1)

Joe Ratzer
Joe Ratzer

Reputation: 18569

I would prefer to keep it simple and see the View changed by adding, for example, &#58;.

The text "Address" is bound to be used somewhere else where a colon or dash isn't required.

Upvotes: 2

Related Questions