Note that there are some explanatory texts on larger screens.

plurals
  1. PO$.each(someData.split(',') => returns concatenated string, instead of array of items
    primarykey
    data
    text
    <p>I'm using asp.net mvc - ajax with jQuery... I've a model type named "<strong>Books</strong>" that contains a property "<strong>TableOfContents</strong>" this property contains data in the following format:</p> <pre><code>TableOfContents = "1,2,4,6,9,17,28"; </code></pre> <p>Json action method, that reuturn Book object look like this:</p> <pre><code>public JsonResult GetBook(int id) { return Json(_bookRepository.Current(id), .....AllowGet); } </code></pre> <p>Following style of list images that I want to display.</p> <p><img src="https://i.stack.imgur.com/B1W3h.gif" alt="alt text"></p> <p>In C# (Razor) I can do this,</p> <pre><code>var splitted = Model.TableOfContents.Split(‘,’); @foreach(var number in splitted) { &lt;li&gt;&lt;img src=”@Url.Content(“~/Content/Images/img-“ + number + “.gif”)” /&gt; &lt;/li&gt; } </code></pre> <p>This code 100% works and shows images as shown in the above image.</p> <p>The same thing I want to done with jQuery because I’m using ASP.NET MVC Ajax with jQuery. Here is the jQuery script through with I get data from MVC via jQuery.</p> <pre><code>&lt;script type="text/javascript"&gt; function GetBook(id) { var url = '@Url.Content("~//Monthly/CurrentBook?id=")' + id; $.post(url, null, function (book) { $('#bookResult' + book.ID).html( '&lt;a href="@Url.Content("~/BookDetails/")' + book.ID + '"&gt;Click to View Details&lt;/a&gt;' + '&lt;div&gt;&lt;p style=" text-align:center;"&gt;' + '&lt;a href="' + monthly.URL + '"&gt;&lt;button style="background-image:url(@Url.Content("~/Content/Images/download-pdf.gif")); width:200px; height:70px;" /&gt;&lt;/a&gt;' + '**&lt;!-- Here I want to use jQuery Code for displaying Table of content Images --&gt;**' + '&lt;/p&gt;&lt;/div&gt;'); }, 'json' ); } &lt;/script&gt; </code></pre> <p>I used jQuery code like this:</p> <pre><code>$.each(book.TableOfContents.split(','), function(number) { + '&lt;li&gt;&lt;img src="img-' + number + '.gif" /&gt;&lt;/li&gt;' } </code></pre> <p>But it displays result as: "1,2,3,17,90" (in string format instead of displaying images)</p> <p>In ASP.NET MVC Razor, I can display list of images like this:</p> <pre><code> var splitted = Model.TableOfContents.Split(‘,’); @foreach(var number in splitted) { &lt;li&gt;&lt;img src=”@Url.Content(“~/Content/Images/img-“ + number + “.gif”)” /&gt; &lt;/li&gt; } </code></pre> <p><a href="http://alhadith.cz.cc" rel="noreferrer">http://alhadith.cz.cc</a> (this webite's main page displays list of images with ASP.NET MVC Razor)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload