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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:41:32+00:00 2026-05-25T11:41:32+00:00

I have a simple question. I have a model that looks like this: public

  • 0

I have a simple question.

I have a model that looks like this:

public class AddEditChildProductModel
{
    public string Name {get; set;}
    public string Sku {get;set;}
    ........
    public IEnumerable<AddEditPriceTierModel> PriceTiers {get;set;}
}
public class AddEditPriceTierModel
{
    public int QtyStart {get;set;}
    public int QtyEnd {get;set;}
    ........
}

My question is how do I edit the collection in the same view?

It would seem this would be very simple, maybe I am missing something.

Thanks!!

**Edit**

OK, so I used EditorTemplates, but now I am getting the following error:

The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.

This is my controller action:

public ActionResult EditChildProduct(AddEditChildProductModel model)
        {
            if (!ModelState.IsValid)
                return PartialView("AddEditChildProduct", model);

            ChildProduct childProduct = productService.GetChildProductByID(model.ID);
            AutoMapper.Mapper.Map<AddEditChildProductModel, ChildProduct>(model, childProduct);
            foreach (var tier in childProduct.PriceTiers)
            {
                tier.ChildProduct = childProduct;
            }
            UnitOfWork.Commit();

            return ListChildProducts(model.ProductID);
        }

Shouldn’t this work, as I get the ChildProduct with the related PriceTiers collection and use AutoMapper to map the differences? I maintain hidden fields for the PK and FK fields on the PriceTier.

I am a bit confused.

  • 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-25T11:41:33+00:00Added an answer on May 25, 2026 at 11:41 am

    You could use editor templates:

    @model AddEditChildProductModel
    @using (Html.BeginForm())
    {
        <div>
            @Html.LabelFor(x => x.Name)
            @Html.EditorFor(x => x.Name)
            @Html.ValidationMessageFor(x => x.Name)
        </div>
    
        <div>
            @Html.LabelFor(x => x.Sku)
            @Html.EditorFor(x => x.Sku)
            @Html.ValidationMessageFor(x => x.Sku)
        </div>
    
        <table>
            <thead>
                <tr>
                    <th>QtyStart</th>
                    <th>QtyEnd</th>
                </tr>
            </thead>
            <tbody>
                @Html.EditorFor(x => x.PriceTiers)
            </tbody>
        </table>
    
        <input type="submit" value="OK">
    }
    

    and then define the editor template which will be rendered for each element of the PriceTiers list (~/Views/Shared/EditorTemplates/AddEditPriceTierModel.cshtml) – the name and location of the editor template is important. You could also put it in ~/Views/SomeController/EditorTemplates/AddEditPriceTierModel.cshtml if the editor template is specific only for a given controller:

    @model AddEditPriceTierModel
    <tr>
        <td>
            @Html.LabelFor(x => x.QtyStart)
            @Html.EditorFor(x => x.QtyStart)
            @Html.ValidationMessageFor(x => x.QtyStart)
        </td>
        <td>
            @Html.LabelFor(x => x.QtyEnd)
            @Html.EditorFor(x => x.QtyEnd)
            @Html.ValidationMessageFor(x => x.QtyEnd)
        </td>
    </tr>
    

    and now your POST controller action signature will look like this:

    [HttpPost]
    public ActionResult Edit(AddEditChildProductModel model)
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that looks something like this: public class SampleModel { public
this seems like a really simple Question...but behold :) Geek name:string Laser geek_id:integer, power:integer
I have a Friendship model which looks like this: from_user = ForeignKey(User, related_name='friends') to_user
From this question , it looks like it makes sense to have a controller
A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
I have a simple question, but I'm about 80% sure that the answer to
I have a simple question that I am posing mostly for my curiousity. What
I have a simple django app that is using only the admin. This is
Following on from this question , I'm using a simple ViewModel class to test
This is probably a very simple question, but at this time I have myself

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.