-1

So I am using textareas in a form to taking a list.

<tr>
   <td><label asp-for="Ingredients"></label></td>
   <td><textarea asp-for="Ingredients" ></textarea></td>
   <td><span asp-validation-for="Ingredients"></span></td>
</tr>

In my viewModel I have

[Required]
public string Ingredients { get; set; }

In the details it is called using

<div style="margin-left:15px"><u>Instructions:</u> <br /> 
@Model.Instructions</div>  <br />

It ends up displaying like:

item 1, item 2, item 3

I want it to display like:

item1
item2
item3

So how do I split the ingredients at the commas without displaying them while dropping them down a line each?

LarsTech
  • 80,625
  • 14
  • 153
  • 225

1 Answers1

1

Note, it really doesn't matter if you're pulling from a database or not - a string is a string is a string.

Given that, on any string you can use String.Split to break it into an array based on some delimiter such as ',' in your case. Then use String.Join to make that array back into a string, joining with either markup (such as "<br />") or System.Environment.NewLine for more of a plaintext representation.

Rick Riensche
  • 1,050
  • 1
  • 12
  • 25