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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:09:48+00:00 2026-05-15T19:09:48+00:00

Using MVC 2 I have been trying to make this record store project. Creating

  • 0

Using MVC 2 I have been trying to make this record store project.
Creating records work but updating them doesn’t. No exceptions are thrown either.

I examined getchangeset() right before submitchanges() it shows all zeros.

Thanks for your reading and you help 🙂

The Edit view:

<% using (Html.BeginForm("Edit", "Song")) { %>
    <fieldset>          
            <%: Html.HiddenFor(model => model.SongID) %>
            <%: Html.HiddenFor(model => model.DownloadCount) %>
            <%: Html.HiddenFor(model => model.Rating) %>
            <%: Html.HiddenFor(model => model.TagMapID) %>

        <div class="editor-label">
            <%= Html.LabelFor(model => model.AlbumID) %>
        </div>
        <div class="editor-field">
            <%= Html.DropDownListFor(model => model.AlbumID, DataHelper.getAlbumList(Model.AlbumID)) %>
            <%= Html.ValidationMessageFor(model => model.AlbumID) %>
        </div>

        <div class="editor-label">
            <%= Html.LabelFor(model => model.FullName) %>
        </div>
        <div class="editor-field">
            <%= Html.TextBoxFor(model => model.FullName)%>
            <%= Html.ValidationMessageFor(model => model.FullName) %>
and so on...

Edit function

public ActionResult Edit(int id)
    {
        try
        {
            var model = songRepository.Song.Single(rec => rec.SongID == id);

            return View(model);
        }
        catch (Exception anyEx)
        {
            throw anyEx;
            //return View("Error")
        }
    }

Edit post function

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(Song model)
    {
        try
        {
            if (ModelState.IsValid)
            {
                songRepository.SaveSong(model);
                TempData["adminmsg"] = "Song saved";
                return RedirectToAction("List", "Song");
            }
            else
            {
                TempData["adminmsg"] = "Song not saved";
                return View("Edit", model);
            }
        }
        catch (Exception anyEx)
        {
            throw anyEx;
        }
    }

This is what saveSong() looks like in SqlSongRepository

public void SaveSong(Song song)
    {
        if (song.SongID == 0)
        {
            songTable.InsertOnSubmit(song);
        }
        else
        {
            songTable.Attach(song);
            songTable.Context.Refresh(RefreshMode.KeepChanges, song);
        }

        songTable.Context.SubmitChanges();
    }

[Context things]

This is the context repository

public class ContextRepository : IContextRepository
{
    private string connStr;

    public ContextRepository(string connectionString)
    {
        this.connStr = connectionString;
    }

    public DataContext MasterContext
    {
        get { return new DataContext(connectionString); }
    }

    public string connectionString
    {
        get { return connStr; }
    }
}

In the song controller for example

public SongController(IContextRepository contextRepository)
    {
        this.contextRepository = contextRepository;
        MasterContext = this.contextRepository.MasterContext;
        DataHelper.InitContext(contextRepository);

        songRepository = new SqlSongRepository(contextRepository.connectionString);
    }

Then the songRepository is used as I posted before.

  • 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-15T19:09:48+00:00Added an answer on May 15, 2026 at 7:09 pm

    Well, solved the problem. Changing

    songTable.Context.Refresh(RefreshMode.KeepChanges, song);
    

    to

    songTable.Context.Refresh(RefreshMode.KeepCurrentValues, song);
    

    did the trick.

    I don’t know why, it would be great if someone could explain.

    Thanks!

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I see a few problems. .sub-menu has that dash so… May 16, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer With the release of WebORB for .NET 4.0 came new… May 16, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer This post demonstrates how to configure this: http://atombrenner.blogspot.com/2010/07/how-to-change-resharper-naming-style.html UPDATE: The… May 16, 2026 at 3:56 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

Related Questions

This might be too opinionated a question, but looking for help! I have been
I'm new to MVC, but I've been all over this, read all the documentation
I've been experimenting with ASP.Net MVC, and have come across a problem that is
We have been using weborb for .net on an existing application for some time
Hopefully this explanation will make sense, but what is the best way (if it
I've been searching for tutorials to better understand this, but I'm having no luck.
I have been using jQuery for the past couple of years now, and I'm
I have been googling and stackoverflowing for the last two hours and couldn't find
I have a very simple MVC site that is returning a 404 not found
I have put together a small ASP.NET MVC 2 site that does some very

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.