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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:02:50+00:00 2026-06-11T19:02:50+00:00

In a web page, when a user deletes rows from a datatable, should I

  • 0

In a web page, when a user deletes rows from a datatable, should I be using the view’s model or the datatable to do the data manipulation? (I’m learning MVC 4, and I’m not sure if accessing the model causes a hit to the server.)

Here’s a quick example of what I’m trying to do. In my controller, I’m returning some Person objects:

public ActionResult Index()
{
    List<Person> people = new List<Person>();
    people.Add(new Person() { Id = 1, FirstName = "Geddy", LastName = "Lee" });
    people.Add(new Person() { Id = 2, FirstName = "Alex", LastName = "Lifeson" });
    // more people here...

    return View(people);
}

This is how my view references people (first line in view):

@model List<MiscCommon.Entities.Person>

In my view, I’m using datatables to display. That part is working just fine.

datatables views

In my javascript function, I’m successfully able to pass the ID when the user hits delete (the x) on a row in the table. However, I’m not sure if I should manipulate the datatable directly (as shown below), or if I should be modifying @model then refreshing the datatable. Which way is considered correct? Or is there even another approach that I’m not aware of?

function RemovePerson(personIdToDelete) {
    var oTable = $('#tablePeople').dataTable();
    var rows = oTable.fnGetNodes();
    var rowToDelete;

    for (var i = 0; i < rows.length; i++) {
        var idFromCurrentRow = oTable.fnGetData(i, 1);  // ID column
        if (idFromCurrentRow == personIdToDelete) {
            rowToDelete = i;
        }                
    }

    oTable.fnDeleteRow(rowToDelete);
}

Note: I’m using the model to populate the table in the first place:

@foreach (var person in Model) {
                @:$('#tablePeople').dataTable().fnAddData([@MvcHtmlString.Create(string.Format("'<a href=\"\", onclick=\"RemovePerson({0}); return false;\">x</a>'", @person.Id)), '@person.FirstName', '@person.LastName']);
            }
  • 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-11T19:02:52+00:00Added an answer on June 11, 2026 at 7:02 pm

    Your @model only exists server-side. Once the DOM is rendered and sent to the client, the @model is disposed. You need to contact the server again to let database know that record should be deleted. You have two options to do that:

    Option One

    Contact the server during your RemovePerson function in Javascript via AJAX.

    Option Two

    Post the entire page back to the server and parse the results. This would require your table being wrapped in a form and an input for each one of your rows.

    I prefer to use option one and using the jQuery.ajax() method found here.

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

Sidebar

Related Questions

new on rails and using windows for now,, i have web page that user
I'd like my web page to allow the user to add data, even when
I am developing a web-based user interface that plots some data from a database
When I try user = System.Web.UI.Page.CurrentUser or user = System.Web.UI.Page.User.Identity I get an error
I've got a web page where the user can add a new item to
I have a list of items on my web page that the user can
Im trying to display some files in a web page so the user can
I have a web page that prompts for user input via DropDownLists in some
I have a web page that uses three controls to allow a user to
This is how my web page looks like: PosisionDataView is a web user control,

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.