Michael Harvey Michael Harvey - 8 months ago 44
Vb.net Question

How do I escape the period of a file extension using razor?

I have a view in which I'm using passing viewmodel which has a property called FileName. This property is supposed to contain the file extension of a selected file however only the file extension shows. For example if the file name is Items.csv, then only "csv" will show up. Not ".csv", just "csv". I've tried to add the file extension in the property itself and also on the view by doing the following:

@Using (Html.BeginForm("CreatePrintJobStepLast", "Marketing"))
<div class="section main">
File Name : @Html.Label(String.Format("{0}{1}", Model.FileName, ".csv"))
<br />
File Name : @Html.Label(String.Format("{0}.{1}", Model.FileName, "csv"))
<br />
File Name : @Html.Label(String.Format("{0}{1}{2}", Model.FileName, ".", "csv"))
End Using

I've tried a couple other ways, but the outcome is still the same. The user still sees "csv". Any help would be greatly appreciated and thank you in advance for taking time to look at my issue.


The first attribute of the Html.Label(...) helper is used to fill the for HTML attribute. So, you could have the following:

File Name : @Html.Label("", String.Format("{0}{1}", Model.FileName, ".csv"))