Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I escape quotes inside attribute in razor pages

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"})"
like image 760
Maksym Avatar asked Oct 28 '25 08:10

Maksym


1 Answers

Try This:

asp-items='@new SelectList(Model.Stocks, "Id", "Name")'
like image 177
Derviş Kayımbaşıoğlu Avatar answered Oct 31 '25 01:10

Derviş Kayımbaşıoğlu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!