Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6860631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:25:57+00:00 2026-05-27T02:25:57+00:00

I have the following code in an MVC 3 view <% foreach (var stockItem

  • 0

I have the following code in an MVC 3 view

    <% foreach (var stockItem in Model.Shop.Stock) { %>
        <div class="shopItem">
            <div class="shopItemLeft">
                <% Html.RenderPartial("ItemImageDisplay", stockItem.Item); %>
            </div>
            <div class="shopItemRight">
                <strong><%= stockItem.Item.ToString() %></strong><br />
                <%= stockItem.Item.CalculatePrice() %><br />
                <%= stockItem.Quantity %> in stock<br />
                <%= Html.ActionLink("Buy", "BuyShopItem", new { shopId = Model.Shop.Id, itemId = stockItem.Item.Id }, null) %>
            </div>
        </div>
    <% } %>

When this is rendered, the “ItemImageDisplay” partial view is not inside the div tag that I have placed it in, it instead renders as if I had put:

    <% foreach (var stockItem in Model.Shop.Stock) { %>
                <% Html.RenderPartial("ItemImageDisplay", stockItem.Item); %>
    <% } %>

    <% foreach (var stockItem in Model.Shop.Stock) { %>
        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong><%= stockItem.Item.ToString() %></strong><br />
                <%= stockItem.Item.CalculatePrice() %><br />
                <%= stockItem.Quantity %> in stock<br />
                <%= Html.ActionLink("Buy", "BuyShopItem", new { shopId = Model.Shop.Id, itemId = stockItem.Item.Id }, null) %>
            </div>
        </div>
    <% } %>

The html of the partial view is as follows:

<%= Html.Image("~/Content/Images/Items/" + Model.Id + ".png", Model.ToString(), new { onmouseover = "tooltip('item:" + Model.Id + "');", onmousemove = "tooltip('item:" + Model.Id + "');", onmouseout = "tooltipRem();" }) %>

Please can you help me to understand why this is rendering as it is and what I can do to stop this from happening?

EDIT: Here is the rendered output for this section:

<img alt="Can of Pineapples" onmousemove="tooltip(&#39;item:1152&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:1152&#39;);" src="/Content/Images/Items/1152.png" title="Can of Pineapples" /><img alt="Kraken Treats" onmousemove="tooltip(&#39;item:1104&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:1104&#39;);" src="/Content/Images/Items/1104.png" title="Kraken Treats" /><img alt="Orange Jelly" onmousemove="tooltip(&#39;item:1279&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:1279&#39;);" src="/Content/Images/Items/1279.png" title="Orange Jelly" /><img alt="Peanuts" onmousemove="tooltip(&#39;item:509&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:509&#39;);" src="/Content/Images/Items/509.png" title="Peanuts" /><img alt="Fourth Year Anaversary Cake" onmousemove="tooltip(&#39;item:859&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:859&#39;);" src="/Content/Images/Items/859.png" title="Fourth Year Anaversary Cake" /><img alt="Taco" onmousemove="tooltip(&#39;item:486&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:486&#39;);" src="/Content/Images/Items/486.png" title="Taco" /><img alt="Can of Blueberries" onmousemove="tooltip(&#39;item:1154&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:1154&#39;);" src="/Content/Images/Items/1154.png" title="Can of Blueberries" /><img alt="Strawberry Jam" onmousemove="tooltip(&#39;item:639&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:639&#39;);" src="/Content/Images/Items/639.png" title="Strawberry Jam" /><img alt="Crisps" onmousemove="tooltip(&#39;item:726&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:726&#39;);" src="/Content/Images/Items/726.png" title="Crisps" /><img alt="Cooked Shrimp" onmousemove="tooltip(&#39;item:521&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:521&#39;);" src="/Content/Images/Items/521.png" title="Cooked Shrimp" /><img alt="Fishy Finger" onmousemove="tooltip(&#39;item:629&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:629&#39;);" src="/Content/Images/Items/629.png" title="Fishy Finger" /><img alt="Can of Peaches" onmousemove="tooltip(&#39;item:1151&#39;);" onmouseout="tooltipRem();" onmouseover="tooltip(&#39;item:1151&#39;);" src="/Content/Images/Items/1151.png" title="Can of Peaches" />

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Can of Pineapples</strong><br />
                940<br />
                10 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=1152">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Kraken Treats</strong><br />
                934<br />
                7 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=1104">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Orange Jelly</strong><br />
                827<br />
                9 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=1279">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Peanuts</strong><br />
                116<br />
                8 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=509">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Fourth Year Anaversary Cake</strong><br />
                1794<br />
                7 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=859">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Taco</strong><br />
                950<br />
                7 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=486">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Can of Blueberries</strong><br />
                317<br />
                8 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=1154">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Strawberry Jam</strong><br />
                1032<br />
                10 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=639">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Crisps</strong><br />
                179<br />
                10 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=726">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Cooked Shrimp</strong><br />
                663<br />
                11 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=521">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Fishy Finger</strong><br />
                974<br />
                10 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=629">Buy</a>
            </div>
        </div>

        <div class="shopItem">
            <div class="shopItemLeft">

            </div>
            <div class="shopItemRight">
                <strong>Can of Peaches</strong><br />
                786<br />
                7 in stock<br />
                <a href="/Market/BuyShopItem?shopId=1&amp;itemId=1151">Buy</a>
            </div>
        </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:25:57+00:00Added an answer on May 27, 2026 at 2:25 am

    Hmm i suspect it is because you are using Html.RederPartial rather than Html.Partial. The latter returns a string whereas the former writes directly to the response stream. I have a sneaky feeling that MVC is executing the entire foreach loop and then writing to the response at the end which would explain your results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code in an asp.net mvc view. <% = Html.DropDownList(Filter, new
i have the following code in the asp.net mvc view if (isLoggedInUserAdmin) {%> <%=Html.ActionLink(View,
I am using Spring MVC 3, NetBeans I have the following model, public class
I have the following code in a MVC User Control (the field names have
This is a beginner level question for asp.net MVC I have the following code
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following code class User attr_accessor :name end u = User.new u.name =
i have following code to show div on page <div id=all_users> <div id=user11 userid=11
i'm new to routing in aspnet mvc.. i have following code: Action Controller public
I have the following code repeated several times in a mvc app. public ActionResult

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.