Home > DeveloperSection > Forums > Inserting literal values along with razor into javascript
F Scott Fitzgerald
F Scott Fitzgerald

Total Post:29

Points:203
Posted on    July-08-2013 8:23 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 1 Reply(s)
 1208  View(s)
Rate this:
Hi Expert!

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()", 
                 }


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    July-08-2013 8:30 AM

Hi F Scott!

Just try this:

@foreach (DateEarningsViewClass d in Model.dateEarnings) {
   @Html.Raw("\"" + d.date.ToShortDateString() + "\"")
}

Don't want to miss updates? Please click the below button!

Follow MindStick