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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:24:26+00:00 2026-06-03T05:24:26+00:00

in my code the update takes place both in the view and in the

  • 0

in my code the update takes place both in the view and in the controller. Same Controller and View for both create and Update. Create profile works fine. but while updating it shows DbConcurrency exception Message. Please help me to find.

Exception Message while updating the record:
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

My Update profile page has (Profile.cshtml)

@model Sitecss.Models.Profile
           @using Microsoft.Web.Helpers;
@{
    ViewBag.Title = "CreateProfile";
    Layout = "~/Views/Shared/_HomeLay.cshtml";
}



@{
    var GT = new SelectList(new[] {
        new {ID ="Team DeathMatch", Name="Team DeathMatch"},
        new {ID ="Search & Destroy", Name="Search & Destroy"},
        new {ID ="Flag Runner", Name="Flag Runner"},
        new {ID ="Domination", Name="Domination"},
        new {ID ="Kill Confirmed", Name="Kill Confirmed"}
    },"ID","Name");
    var Spec = new SelectList(new []{
        new {ID ="Assault", Name="Assault"},
        new {ID ="Tactical", Name="Tactical"},
        new {ID ="Long-Range Eliminations", Name="Long-Range Eliminations"},
        new {ID ="Noob", Name="Noob"}
    }, "ID", "Name");

}


<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>


@using (Html.BeginForm("CreateProfile", "Home", FormMethod.Post, new { @encType = "multipart/form-data" }))
{

    <div id="content1">
    @Html.ValidationSummary(true)
<h4>Create a Profile</h4>

    <div>
    @Html.LabelFor(m => m.SteamName)
    </div>
    <div>
    @Html.TextBoxFor(m => m.SteamName, new { @class = "wide" })
    @Html.ValidationMessageFor(m => m.SteamName)
    </div>

    <div>
    @Html.LabelFor(m =>m.UserImg)
    </div>
    <div>

    <input type="file" name="image" class="image" /> <br />
    </div>

    <div>
    @Html.LabelFor(m => m.GameType)
    </div>
    <div>
    @Html.DropDownListFor(m => m.GameType, GT, new { @class = "wide" })
    @Html.ValidationMessageFor(m => m.GameType)
    </div>

    <div>
    @Html.LabelFor(m => m.Specialist)
    </div>
    <div>
    @Html.DropDownListFor(m => m.Specialist, Spec, new { @class = "wide" })
    @Html.ValidationMessageFor(m => m.Specialist)
    </div>

    <div>
    @Html.LabelFor(m => m.FavGun)
    </div>
    <div>
    @Html.TextBoxFor(m => m.FavGun, new { @class = "wide" })
    @Html.ValidationMessageFor(m => m.FavGun)
    </div>
    <p><input type="submit" class="button" value="Ok" /></p>
    </div>
}

while my controller functions are

public ActionResult CreateProfile()
        {
            if (db.Profiles.Any(u => u.Username == User.Identity.Name))
            {
                Profile pro = (from usr in db.Profiles where usr.Username == User.Identity.Name select usr).Single();
                olf = pro.UserImg;
                Profile p = db.Profiles.Find(pro.Id);
                ViewBag.ProfilePic = olf;
                return View(p);
            }
            else
            {
                ViewBag.Name = User.Identity.Name;
                return View();
            }
        }


   [HttpPost]
        public ActionResult CreateProfile(Profile m)
        {
            WebImage photo = WebImage.GetImageFromRequest();

            string newFileName = "";
            string thumbs = "";
            if (photo != null)
            {
                string ext = Path.GetExtension(photo.FileName);
                newFileName = User.Identity.Name+ ext;
                thumbs = @"Images/" + newFileName;
                photo.Resize(width: 120, height: 120, preserveAspectRatio: true, preventEnlarge: true);
                photo.Save(@"~/"+thumbs);
                m.UserImg = newFileName;
            }

            if (ModelState.IsValid)
            {    
                if (db.Profiles.Any(u => u.Username == User.Identity.Name))
                {   

                    db.Entry(m).State = System.Data.EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");

                }
                else
                {
                    m.Username = User.Identity.Name;
                    db.Profiles.Add(m);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            return View(m);
        }
  • 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-06-03T05:24:27+00:00Added an answer on June 3, 2026 at 5:24 am

    While Adding Breakpoint to the update statement in my edit Controller I came to know that the primary key Id =0 on update in order to fix this issue I have added Hidden Field in the view that has fixed the DbConcurrency on update

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

Sidebar

Related Questions

I use this code to update data in database table. Can reuse same code
I have this code to update users data, but I can't write the for
I use below code to update listview. setListAdapter(MyAdapter); MyAdapter.notifyDataSetChanged(); getListView().setEmptyView(empty); But each time update,
I am trying to update code via Linq, but I am getting this error:
The Javadoc for AsynchronousByteChannel.read() says the operation takes place asynchronously, but what happens when
Update : I edited the code, but the problem persists... Hi everyone, this is
I have the following code: UPDATE myTable SET Col1 = @Value However, I have
Here is my upsert code: UPDATE LastTicket SET LastTicketNumber=LastTicketNumber+1 OUTPUT INSERTED.LastTicketNumber WHERE CategoryId='1'; IF
You've pushed a code update to a daemontools service and want to restart it
I have some code to update a database table that looks like try {

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.