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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:29:05+00:00 2026-05-15T01:29:05+00:00

In C# ASP.NET MVC application I use Link to SQL to provide data for

  • 0

In C# ASP.NET MVC application I use Link to SQL to provide data for my application. I have got simple database schema like this:
My database

In my controller class I reference this data context called Model (as you can see on the right side of picture in properties) like this:

private Model model = new Model();

I’ve got a table (List) of Series rendered on my page. It renders properly and I was able to add delete functionality to delete Series like this:

public ActionResult Delete(int id) {
    model.Series.DeleteOnSubmit(model.Series.SingleOrDefault(s => s.ID == id));
    model.SubmitChanges();
    return RedirectToAction("Index");
}

Where appropriate action link looks like this:

<%: Html.ActionLink("Delete", "Delete", new { id=item.ID })%>

Also create (implemented in similar way) works fine. However edit does not work. My edit looks like this:

public ActionResult Edit(int id) {
    return View(model.Series.SingleOrDefault(s => s.ID == id));
}

[HttpPost]
public ActionResult Edit(Series series) {

    if (ModelState.IsValid) {
        UpdateModel(series);

        series.Title = series.Title + " some string to ensure title has changed";
        model.SubmitChanges();

        return RedirectToAction("Index");
    }
    return View(series);
}

I have controlled that my database has a primary key set up correctly. I debugged my application and found out that everything works as expected until the line with model.SubmitChanges();. This command does not apply the changes of Title property(or any other) against the database.

Please help.

EDIT:
If I add this line: model.Series.Attach(series); just before model.SubmitChanges(); there is no change – edits still does not reflect to database. The instance passed to Edit method as a parameter is already attached to the data context model.

EDIT:
Code of view that belongs to method Edit:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<TVSeriesInfoApp.Models.Series>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Edit
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>Edit</h2>

<% using (Html.BeginForm()) {%>
    <%: Html.ValidationSummary(true) %>

    <fieldset>
        <legend>Fields</legend>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.Title) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.Title) %>
            <%: Html.ValidationMessageFor(model => model.Title) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.Seasons) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.Seasons) %>
            <%: Html.ValidationMessageFor(model => model.Seasons) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.Stars) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.Stars) %>
            <%: Html.ValidationMessageFor(model => model.Stars) %>
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>

<% } %>

<div>
    <%: Html.ActionLink("Back to List", "Index") %>
</div>

</asp:Content>
  • 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-15T01:29:06+00:00Added an answer on May 15, 2026 at 1:29 am

    This is what our Edit Action would look like (Adjusted for your model):

    [HttpPost]
    public ActionResult Edit(int id, Series series)
    {
        Series updatingSeries = model.Series.Single(s => s.ID == id);
    
        try
        {
            TryUpdateModel(updatingSeries);
            model.SubmitChanges();
    
            return RedirectToAction("Details", new { id = updatingSeries.ID });
        }
        catch
        {
            return View(updatingSeries);
        }
    }
    

    This can happen because the ModelState might not be valid in some cases. Have you done something to the View? Can you also post your View Code here please?

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

Sidebar

Ask A Question

Stats

  • Questions 408k
  • Answers 408k
  • 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 are you saying that you want to do this? View… May 15, 2026 at 6:48 am
  • Editorial Team
    Editorial Team added an answer The problem is BinaryWriter doesn't have a BeginWrite function so,… May 15, 2026 at 6:48 am
  • Editorial Team
    Editorial Team added an answer Ok, so I figured this out, I think. If I… May 15, 2026 at 6:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.