3

I'm trying to pass two strings as parameters for constructor which is already embedded inside attribute with double quotes:

 <select asp-for="Employee.StockId" asp-items="@new SelectList(Model.Stocks, "Id", "Name")" class="form-control"></select>

I've tried escaping with backslashes or @ but still no success.

Edit: So, there are two options which actually worked:

asp-items='@new SelectList(Model.Stocks, "Id", "Name")'
asp-items="@new SelectList(Model.Stocks,@{"Id"}, @{"Name"})"
Maksym
  • 35
  • 7

1 Answers1

3

Try This:

asp-items='@new SelectList(Model.Stocks, "Id", "Name")'
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
  • First one is not valid but the second is. Actually I found out that `@{"Id"}, @{"Name"}` also works. – Maksym Jan 24 '19 at 16:32