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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:56:15+00:00 2026-05-31T08:56:15+00:00

MVC 3, VB.NET, RAZOR app, using EF. I am having an issue in my

  • 0

MVC 3, VB.NET, RAZOR app, using EF. I am having an issue in my post function with the database not updating at all… Using a break at db.savechanges() I look at the variable and all of the correct information is contained in the UpdateModel( ) part. But no dice the code executes and returns no errors so all looks fine but when I look at the database table it has not been changed at all, all of the old values are still present.. Function is as follows:

   <AcceptVerbs(HttpVerbs.Post)>
    Function EditCourse(ByVal _eCourse As cours) As ActionResult
        Dim id As Integer = _eCourse.course_id

            Dim _filename As String = String.Empty
            Dim _guid As String = String.Empty

            Dim _count As Integer = 0
            Dim _courseFiles As cours = db.courses.Where(Function(f) f.course_ref = _eCourse.course_ref).First

            Dim _file1 As String = _courseFiles.handoutFile1
            Dim _file2 As String = _courseFiles.handoutFile2
            Dim _file3 As String = _courseFiles.handoutFile3
            Dim _file4 As String = _courseFiles.handoutFile4
            Dim _file5 As String = _courseFiles.handoutFile5
            Dim _file6 As String = _courseFiles.handoutFile6
            Dim _file7 As String = _courseFiles.handoutFile7
            Dim _file8 As String = _courseFiles.handoutFile8
            For Each File As String In Request.Files
                _count += 1
                Dim hpf As HttpPostedFileBase = TryCast(Request.Files(File), HttpPostedFileBase)
                If hpf.ContentLength = 0 Then
                    Continue For
                End If

                Dim savedfileName As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + hpf.FileName
                hpf.SaveAs(savedfileName)
                _filename = hpf.FileName

                Select Case _count
                    Case Is = 1
                        If Not String.IsNullOrWhiteSpace(_file1) Then
                            If Not String.Compare(_eCourse.handoutFile1, _file1) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile1) Then
                                Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file1
                                If System.IO.File.Exists(FileToDelete) = True Then
                                    System.IO.File.Delete(FileToDelete)
                                End If
                            End If
                        End If
                        _eCourse.handoutFile1 = _filename

                    Case Is = 2
                        If Not String.IsNullOrWhiteSpace(_file2) Then
                            If Not String.Compare(_eCourse.handoutFile2, _file2) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile2) Then
                                Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file2
                                If System.IO.File.Exists(FileToDelete) = True Then
                                    System.IO.File.Delete(FileToDelete)
                                End If
                            End If
                        End If
                        _eCourse.handoutFile2 = _filename

                    Case Is = 3
                        If Not String.IsNullOrWhiteSpace(_file3) Then
                            If Not String.Compare(_eCourse.handoutFile3, _file3) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile3) Then
                                Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file3
                                If System.IO.File.Exists(FileToDelete) = True Then
                                    System.IO.File.Delete(FileToDelete)
                                End If
                            End If
                        End If
                        _eCourse.handoutFile3 = _filename

                    Case Is = 4
                        If Not String.IsNullOrWhiteSpace(_file4) Then
                            If Not String.Compare(_eCourse.handoutFile4, _file4) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile4) Then
                                Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file4
                                If System.IO.File.Exists(FileToDelete) = True Then
                                    System.IO.File.Delete(FileToDelete)
                                End If
                            End If
                        End If
                        _eCourse.handoutFile4 = _filename

                    Case Is = 5
                        If Not String.IsNullOrWhiteSpace(_file5) Then
                            If Not String.Compare(_eCourse.handoutFile5, _file5) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile5) Then
                                Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file5
                                If System.IO.File.Exists(FileToDelete) = True Then
                                    System.IO.File.Delete(FileToDelete)
                                End If
                            End If
                        End If
                        _eCourse.handoutFile5 = _filename

                    Case Is = 6
                        If Not String.IsNullOrWhiteSpace(_file6) Then
                            If Not String.Compare(_eCourse.handoutFile6, _file6) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile6) Then
                                Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file6
                                If System.IO.File.Exists(FileToDelete) = True Then
                                    System.IO.File.Delete(FileToDelete)
                                End If
                            End If
                        End If
                        _eCourse.handoutFile6 = _filename

                    Case Is = 7
                        If Not String.IsNullOrWhiteSpace(_file7) Then
                            If Not String.Compare(_eCourse.handoutFile7, _file7) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile7) Then
                                Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file7
                                If System.IO.File.Exists(FileToDelete) = True Then
                                    System.IO.File.Delete(FileToDelete)
                                End If
                            End If
                        End If
                        _eCourse.handoutFile7 = _filename

                    Case Is = 8
                        If Not String.IsNullOrWhiteSpace(_file8) Then
                            If Not String.Compare(_eCourse.handoutFile8, _file8) = 0 AndAlso Not String.IsNullOrWhiteSpace(_eCourse.handoutFile8) Then
                                Dim FileToDelete As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + _file8
                                If System.IO.File.Exists(FileToDelete) = True Then
                                    System.IO.File.Delete(FileToDelete)
                                End If
                            End If
                        End If
                        _eCourse.handoutFile8 = _filename

                End Select

            Next

            UpdateModel(_eCourse)
            db.SaveChanges()


            Return RedirectToAction("CourseIndex")

      End Function

Any Ideas on why this is going wrong?????

  • 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-31T08:56:16+00:00Added an answer on May 31, 2026 at 8:56 am

    You aren’t attaching your _eCourse to your context so it won’t update it.
    UpdateModel I don’t believe is required here at all as that simply takes your posted form values an assigns to your model which you already have since eCourse is a parameter. Do something like (on phone here sorry)
    DB.Entry(_eCourse).State = EntityState.Modified

    And then save changes

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

Sidebar

Related Questions

I started the site using AST.NET Razor template, not ASP.NET MVC template. I recall
For my ASP.NET MVC 3 app (using Razor) my web.config has this: <profile> <providers>
In my ASP.net MVC App (using Razor views) I have a ProductDetails view. This
I have a ASP.Net MVC app with Razor. I try to access a collection
I am using s#arp architecture 2.0 with asp.net mvc 3.0. The razor code in
I have a new ASP.NET MVC 3 project, and MVC and Razor are all
I am using ASP.NET MVC Razor And Data Annotation validators My model: public class
I am using Telerik Date Picker for ASP.Net MVC Razor Form. In this form
I'm having an odd problem with asp.net MVC razor view. I want my model
'm using ASP.NET MVC 3 with Razor views. I have a partial view which

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.