Reputation: 3363
I'm trying to insert quotes AND a value inside a javascript function. I'm doing this through a foreach method call.
@foreach (DateEarningsViewClass d in Model.dateEarnings) {
@d.date.ToShortDateString()
}
The issue is that I want to insert around each date, but I get all sorts of errors when I attempt doing so. How can I do this?
What I essentially wanna display is:
@foreach (DateEarningsViewClass d in Model.dateEarnings) {
"@d.date.ToShortDateString()",
}
Upvotes: 2
Views: 751
Reputation: 44660
Just try this:
@foreach (DateEarningsViewClass d in Model.dateEarnings) {
@Html.Raw("\"" + d.date.ToShortDateString() + "\"")
}
Upvotes: 4
Reputation: 4300
You can use the tag.
@foreach (DateEarningsViewClass d in Model.dateEarnings) {
<text>"</text>
@d.date.ToShortDateString()
<text>"</text>
}
Upvotes: 2