Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Problem in updating records in MVC

Problem in updating records in MVC

Scheduled Pinned Locked Moved LINQ
asp-nethelpcsharpdatabasedebugging
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kmuthuk
    wrote on last edited by
    #1

    Hi there, I'm new to asp.net MVC like many of us. I'm trying to update data in the database through my asp.net MVC web application. Insert works fine but update. I'm using VS2008 SP1. Here is my code snippet, and actually I'm trying an example found in the net. :)

    public ActionResult UpdateMyProduct()
    {
    Models.Product product = new Models.Product();
    UpdateModel(product, Request.Form.AllKeys);
    northwind.SubmitChanges();
    return RedirectToAction("Detail", new { id = product.ProductID });
    }

    When I debug my model doesn't get changed. Am I missing anything? I appreciate any help. Thanks in advance. kmuthuk

    N 1 Reply Last reply
    0
    • K kmuthuk

      Hi there, I'm new to asp.net MVC like many of us. I'm trying to update data in the database through my asp.net MVC web application. Insert works fine but update. I'm using VS2008 SP1. Here is my code snippet, and actually I'm trying an example found in the net. :)

      public ActionResult UpdateMyProduct()
      {
      Models.Product product = new Models.Product();
      UpdateModel(product, Request.Form.AllKeys);
      northwind.SubmitChanges();
      return RedirectToAction("Detail", new { id = product.ProductID });
      }

      When I debug my model doesn't get changed. Am I missing anything? I appreciate any help. Thanks in advance. kmuthuk

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      And where is this UpdateModel method? What does it do? How is your problem related to ASP.NET MVC?


      only two letters away from being an asset

      K 1 Reply Last reply
      0
      • N Not Active

        And where is this UpdateModel method? What does it do? How is your problem related to ASP.NET MVC?


        only two letters away from being an asset

        K Offline
        K Offline
        kmuthuk
        wrote on last edited by
        #3

        UpdateModel is a method of Controller class which updates the MVC Model with the object and its values. In this case, product and product values which are from Request.Form

        N 1 Reply Last reply
        0
        • K kmuthuk

          UpdateModel is a method of Controller class which updates the MVC Model with the object and its values. In this case, product and product values which are from Request.Form

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You're having an issue with updating data and you have a method that updates data but you don't show it? See any problem here?


          only two letters away from being an asset

          K 1 Reply Last reply
          0
          • N Not Active

            You're having an issue with updating data and you have a method that updates data but you don't show it? See any problem here?


            only two letters away from being an asset

            K Offline
            K Offline
            kmuthuk
            wrote on last edited by
            #5

            [^] Actually, I was taking the code from the above article. UpdateFrom of Controller is part of framework, not my own method. This method has been replaced with UpdateModel in SP1. Thanks for your time. Happy Holidays -kmuthuk

            C 1 Reply Last reply
            0
            • K kmuthuk

              [^] Actually, I was taking the code from the above article. UpdateFrom of Controller is part of framework, not my own method. This method has been replaced with UpdateModel in SP1. Thanks for your time. Happy Holidays -kmuthuk

              C Offline
              C Offline
              ColinM123
              wrote on last edited by
              #6

              I think you need to get the record from the DB first, do the update and then submit the changes. There are no changes to be sumbitted to the DB when you create your new class.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups