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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:53:50+00:00 2026-06-14T17:53:50+00:00

Every example that I can find of an MVC4 app has the edit working

  • 0

Every example that I can find of an MVC4 app has the edit working on one row of data at a time. It displays all the rows of data with each row having an edit which takes you to another page and allows you to edit that one row.

What I would like to do is display all the data elements in rows and instead of having the user have to click EDIT on each row, all the rows’ data points would already be in text boxes which the user can directly update. And there is just one SAVE on the page that would just save all the updates/edits at once.

How can I setup my MVC app to support that?

  • 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-14T17:53:52+00:00Added an answer on June 14, 2026 at 5:53 pm

    You can use an EditorTemplates for this. The below example shows the normal form posting example. You can ajaxify it if you need by using the serialize method and sending form values.

    Assuming You need to Edit the List of Student Names for a course. So Let’s create some viewmodels for that

    public class Course
    {
      public int ID { set;get;}
      public string CourseName { set;get;}
      public List<Student> Students { set;get;}
    
      public Course()
      {
        Students=new List<Student>();
      }
    }
    public class Student
    {
      public int ID { set;get;}
      public string FirstName { set;get;}
    }
    

    Now in your GET action method, you create an object of our view model, initialize the Students collection and send it to our strongly typed view.

    public ActionResult StudentList()
    {
       Course courseVM=new Course();
       courseVM.CourseName="Some course from your DB here";
    
       //Hard coded for demo. You may replace this with DB data.
       courseVM.Students.Add(new Student { ID=1, FirstName="Jon" });
       courseVM.Students.Add(new Student { ID=2, FirstName="Scott" });
       return View(courseVM);
    }
    

    Now Create a folder called EditorTemplates under Views/YourControllerName. Then create a new view under that called Student.cshtml with below content

    @model Student
    @{
        Layout = null;
    }
    <tr> 
     <td>
      @Html.HiddenFor(x => x.ID)
      @Html.TextBoxFor(x => x.FirstName ) </td>
    </tr>
    

    Now in our main view (StudentList.cshtml), Use EditorTemplate HTML helper method to bring this view.

    @model Course
    <h2>@Model.CourseName</h2>
    @using(Html.BeginForm())
    {
      <table>
         @Html.EditorFor(x=>x.Students)
      </table>
      <input type="submit" id="btnSave" />
    }
    

    This will bring all the UI with each of your student name in a text box contained in a table row. Now when the form is posted, MVC model binding will have all text box value in the Students property of our viewmodel.

    [HttpPost]
    public ActionResult StudentList(Course model)
    {
       //check for model.Students collection for each student name.
       //Save and redirect. (PRG pattern)
    }
    

    Ajaxified solution

    If you want to Ajaxify this, you can listen for the submit button click, get the form and serialize it and send to the same post action method. Instead of redirecting after saving, you can return some JSON which indicates the status of the operation.

    $(function(){
      $("#btnSave").click(function(e){
        e.preventDefault();  //prevent default form submit behaviour
        $.post("@Url.Action("StudentList",YourcontrollerName")",
                        $(this).closest("form").serialize(),function(response){
       //do something with the response from the action method
        });
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to find an example of a WPF Datagrid that has row
Every example I was able to find demonstrating the w command of sed has
Every example I can find is in C++, but I'm trying to keep my
Why does almost every example I can find (including this question from about a
Every example I can find either goes through creating a table without a gui
It seems like every example I can find of switching between activities involves creating
Every example I can find shows me how to create a project where the
OK, I've tried every single example I can find to do this, sadly most
I want to make a function that automatically turns every Math function global example:
I've ran through several examples over the web, and found that every single time

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.