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 316083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:21:04+00:00 2026-05-12T08:21:04+00:00

I am currently using the EntityFramework to bind my ASP.NET MVC project to a

  • 0

I am currently using the EntityFramework to bind my ASP.NET MVC project to a MySQL database and one of my entities, Product, has an Images property containing a collection of ProductImages. I have built a form to allow the user to modify a given Product and this form includes fields for editing all of the images associated to that Product as well. After reading Phil Haack’s and Dan Miser’s posts on the matter I have a decent idea of what needs to happen, but I can’t seem to make it work for some reason…

Here is my Product form:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<KryptonCMS.Models.Product>" %>
<%@ Import Namespace="KryptonCMS.Core" %>
<%@ Import Namespace="KryptonCMS.Models.ViewModels" %>

<% using (Html.BeginForm())
   {%>

        <ul class="gallery">
            <%
                var index = 0;
                foreach (var image in Model.ImageList.OrderBy(p => p.Order))
                {
            %>
            <li>
                <% Html.RenderPartial("ProductImageForm", image, new ViewDataDictionary(ViewData) { { "index", index } }); %>
            </li>
            <%
                index++;
                }
            %>
        </ul>

    <p>
        <input type="submit" name="btnSave" value="Save" />
        <input type="submit" name="btnCancel" value="Cancel" />
    </p>
<% } %>

And here is the definition for ProductImageForm:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<KryptonCMS.Models.ProductImage>" %>
<%@ Import Namespace="KryptonCMS.Core" %>
<div>
    <%
        var fieldPrefix = string.Format("images[{0}]", ViewData["index"]); %>
    <%=Html.Hidden(fieldPrefix + "ID", Model.ID) %>
    <img src="<%=UtilityManager.GetProductImagePath(Model.Product.ID, Model.FileName, true) %>"
        alt="" /><br />
    <label for="Description">
        Description:</label>
    <%=Html.TextBox(fieldPrefix + "Description", Model.Description) %><br />
    <label for="Order">
        Order:</label>
    <%=Html.TextBox(fieldPrefix + "Order", Model.Order)%><br />
</div>

And finally my ProductsController actions:

    public ActionResult Edit(int id)
    {
        var product = productsRepository.GetProduct(id);

        if (product == null)
            return View("NotFound", new MasterViewModel());

        // else
        return View(ContentViewModel.Create(product));
    }

    [AcceptVerbs(HttpVerbs.Post), ValidateInput(false)]
    public ActionResult Edit(int id, FormCollection formCollection)
    {
        var product = productsRepository.GetProduct(id);

        if (formCollection["btnSave"] != null)
        {
            if (TryUpdateModel(product) && TryUpdateModel(product.Images, "images"))
            {
                productsRepository.Save();

                return RedirectToAction("Details", new { id = product.ID });
            }
            return View(ContentViewModel.Create(product));
        }

        // else
        return RedirectToAction("Details", new { id = product.ID });
    }

The HTML output for a single ProductImageForm looks like this:

<div>
    <input id="images[0]ID" name="images[0]ID" type="hidden" value="1" />
    <img src="/Content/ProductGallery/3/thumbs/car1.jpg"
        alt="" /><br />
    <label for="Description">
        Description:</label>
    <input id="images[0]Description" name="images[0]Description" type="text" value="FAST CAR" /><br />
    <label for="Order">

        Order:</label>
    <input id="images[0]Order" name="images[0]Order" type="text" value="1" /><br />
</div>

I have tried all sorts of methods of reorganizing my form including taking the Image collection out of the Product form and placing it in its own (which I really don’t want to do), but nothing is working. Is there something blatatently wrong with my approach here?

  • 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-12T08:21:04+00:00Added an answer on May 12, 2026 at 8:21 am

    You are missing dots in inputs’ names:

    <%= Html.Hidden(fieldPrefix + ".ID", Model.ID) %>
    <%= Html.TextBox(fieldPrefix + ".Description", Model.Description) %>
    <%= Html.TextBox(fieldPrefix + ".Order", Model.Order) %>
    

    Check this blog post: http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx

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

Sidebar

Ask A Question

Stats

  • Questions 385k
  • Answers 385k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In the Command Window (Ctrl+W, A) you can do simple… May 14, 2026 at 11:29 pm
  • Editorial Team
    Editorial Team added an answer Well, you can easily look up a lot of reference… May 14, 2026 at 11:29 pm
  • Editorial Team
    Editorial Team added an answer Yes - the compiler can't find an appropriate type for… May 14, 2026 at 11:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.