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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:48:03+00:00 2026-05-26T02:48:03+00:00

I am having a problem updating a record. For some reason it is not

  • 0

I am having a problem updating a record. For some reason it is not even hitting the post action in the controller and just returning:
“An item with the same key has already been added.”

It seems to be behaving as if it is doing an insert rather than an update. I would appreciate a new set of eyes on this. It is probably something very simple that I have missed.

Controller:

// GET: /Manage/Regions/Edit/5

    public ActionResult Edit(int id)
    {
        Region_CU regionEdit = (from r in db.Venues_Regions
                                where r.RegionsID == id
                                select new Region_CU
                                {
                                        RegionsID = r.RegionsID,
                                        Name = r.Name,
                                        CalendarLink = r.CalendarLink,
                                        MapIcon = r.MapIcon,
                                        QtrStart = r.QtrStart,
                                        QtrEnd = r.QtrEnd,
                                        FacebookLikeBox = r.FacebookLikeBox,
                                        FacebookId = r.FacebookId
                                    //  region = r 
                                }).Single();
        return View(regionEdit);
    }

    //
    // POST: /Manage/Regions/Edit/5

    [HttpPost]
    public ActionResult Edit(Region_CU r)
    {
        if (ModelState.IsValid)
        {
            var v = db.Venues_Regions.First(i => i.RegionsID == r.RegionsID);
                //v.RegionsID = r.RegionsID;
                v.Name = r.Name;
                v.CalendarLink = r.CalendarLink;
                v.MapIcon = r.MapIcon;
                v.QtrStart = r.QtrStart;
                v.QtrEnd = r.QtrEnd;
                v.FacebookLikeBox = r.FacebookLikeBox;
                v.FacebookId = r.FacebookId;
            //Venues_Regions v = new Venues_Regions
            //{
            //    RegionsID = r.RegionsID,
            //    Name = r.Name,
            //    CalendarLink = r.CalendarLink,
            //    MapIcon = r.MapIcon,
            //    QtrStart = r.QtrStart,
            //    QtrEnd = r.QtrEnd,
            //    FacebookLikeBox = r.FacebookLikeBox,
            //    FacebookId = r.FacebookId
            //};
            //db.Venues_Regions.Attach(v);
            //db.ObjectStateManager.ChangeObjectState(v, EntityState.Modified);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(r);
    }

View :

@model THPT_Razor.Areas.Manage.Models.Region_CU

@{
ViewBag.Title = "Edit Region";
}

<h2>Edit</h2>
<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript">   </script>
<script>
   $(document).ready(function () { $('.date').datepicker({ dateFormat: "mm/dd/yy"   });    });
</script>
@using (Html.BeginForm()) {
  @* @Html.ValidationSummary(true)*@
<fieldset>
    <legend>@Html.DisplayFor(model => model.Name)</legend>

    @Html.HiddenFor(model => model.RegionsID)
    @Html.HiddenFor(model => model.Name)
    @Html.HiddenFor(model => model.CalendarLink)
    <div class="editor-label">
        @Html.Label("Map Icon")
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model => model.MapIcon, new SelectList(Model.mapicons,"id","Description"))
    </div>
    <div class="editor-label">
        @Html.Label("Quarter Start")
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(model => model.QtrStart, new { @class = "date" })
        @Html.ValidationMessageFor(model => model.QtrStart)
    </div>

    <div class="editor-label">
        @Html.Label("Quarter End")
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(model => model.QtrEnd, new { @class = "date" })
        @Html.ValidationMessageFor(model => model.QtrEnd)
    </div>

    <div class="editor-label">
        @Html.Label("Region Facebook ID")
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.FacebookId)
        @Html.ValidationMessageFor(model => model.FacebookId)
    </div>
    <div class="editor-label">
       @Html.Label("Region Facebook LikeBox Code")
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.FacebookLikeBox)
        @Html.ValidationMessageFor(model => model.FacebookLikeBox)
    </div>
    <p>
        <input type="submit" value="Update" />
    </p>
</fieldset>

Edit:

I have received several good suggestions but I guess I have not been clear. Region_CU is not an Entity. Venues_Regions is what I am trying to update. see the comments in the class below for clarification. The original objective was to build a simple wrapper that had the Venues_Regions object and a list object for the map icons. However, the data annotation for the field likebox was not being passed through resulting in the the Venues_Regions object to be broken out. Now when I try to save the update it is not even hitting the http post action. I hope this clears up what I am trying to accomplish and asking for help with. Thanks again for all the help and quick responses.

//create and update
public class Region_CU
{

    public Region_CU()
    {

    }
    public List<MapIcon> mapicons { get; set; }
    //public Venues_Regions region { get; set; }

    // The fields below are what makes up Veunes_Region
    // this was broken out from the above Venues_Region 
    // because the UIHint was not being passed through
    public int RegionsID { get; set; }
    public string Name { get; set; }
    public string CalendarLink { get; set; }
    public int MapIcon { get; set; }
    public DateTime? QtrStart { get; set; }
    public DateTime? QtrEnd { get; set; }

    [UIHint("tinymce_jquery_full"), AllowHtml]
    public string FacebookLikeBox { get; set; }
    public string FacebookId { get; set; }
    public string mapIcon { get; set; }

}

Edit #2:
After a good nights sleep the solution presented itself. In the update action all I needed to do was change from the wrapper being passed in to the Venues_Region object being passed in and now everything works.

Thanks for all the help and suggestions.

Thanks in advance for the help,
Chris

  • 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-26T02:48:04+00:00Added an answer on May 26, 2026 at 2:48 am

    Actually all you need to do is load the venues and call TryUpdateModel. You don’t even need to pass in the object. Then save the venue. Another approach is to use automapper to copy the fields between objects or use the attach method as mentioned but either way no manual field copying is required.

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

Sidebar

Related Questions

I'm not good at JS and I'm having some -I hope- stupid problem I'm
I am trying to learn mysql and having some problem with updating/adding data to
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I'm having a problem updating a row after an inline edit. My ColModel is:
I'm having a problem updating a table and im sure its pretty straight forward
I am having a problem updating the view in android every x seconds. To
I am having a problem with the textbox text updating in my view. I
I am having some trouble updating UMDF drivers using devcon during a standard code-deploy-debug
Hi I'm having a problem updating child objects in the following scenario. The mappings
I'm having a problem updating a control on my ui from a thread created

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.