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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:19:41+00:00 2026-05-23T15:19:41+00:00

I am new to MVC framework and here stucked with an updation method, can

  • 0

I am new to MVC framework and here stucked with an updation method, can anyone help me?

MyCode in View :

       <table>
        <% if (Model == null || Model.Count <= 0)
        {
        %>
        <tr>
        <td >
     No Records found !!.Please search.
     </td>
     </tr>
    <% }
     else
     {
     foreach (var item in Model)
     { %>

     <tr>
     <td>Id</td>
     <td><%: item.ID %></td>

    <tr>
     <td > System : </td>
    <td >                                                                        
     <input id="txtSystemName" value=' <%: item.System %>' type="text"style="height: 20px; width: 120px;" />
     </td>
     <td >TaskName :</td>
    <td><input id="txtTaskName" value='<%: item.TaskName %>' class="TextBoxStyle" type="text"
    style="height: 20px; width: 340px;" /><td/>
    <tr>

    <tr>
    <td><input id="Submit1" name="btnSave" type="submit" value="Save" class="ButtonStyle"
     style="width: 100px; height: 20px" /></td>
    </tr>
<%
}
}
%>

The above is my code and here i will get the records in the view and the above code doesnt contain all the property i have pasted only 3 fields and wen i update some names in the input field and wen i clicked the button in that table i want to update only that record values for this i want to know how to call the controller method and and to pass the parameters to the method.

can anyone help me for this.
thanks in advance.

  • 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-23T15:19:42+00:00Added an answer on May 23, 2026 at 3:19 pm

    Here’s what I would suggest you. Start with a view model which will represent a table row:

    public class MyViewModel
    {
        public int Id { get; set; }
        [Required]
        public string SystemName { get; set; }
        public string TaskName { get; set; }
    }
    

    then a controller which will contain actions for listing all models and updating a single row:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            // I have hardcoded some data here in order to return a list
            // of models => in your case you would probably fetch those from
            // some data source
            var model = Enumerable.Range(1, 7).Select(x => new MyViewModel
            {
                Id = x,
                SystemName = "system " + x,
                TaskName = "task " + x
            });
            return View(model);
        }
    
        [HttpPost]
        public ActionResult Update(MyViewModel model)
        {
            // This action will be responsible for updating the view model
            if (ModelState.IsValid)
            {
                // The model is valid
                // TODO: update it using a repository
                return Json(new { success = true });
            }
            // there was an error => redisplay the view so that the user can fix it
            return PartialView("_MyViewModel", model);
        }
    }
    

    Then let’s move on to the main view (~/Views/Home/Index.aspx):

    <%@ Page 
        Language="C#" 
        MasterPageFile="~/Views/Shared/Site.Master" 
        Inherits="System.Web.Mvc.ViewPage<IEnumerable<AppName.Models.MyViewModel>>" 
    %>
    
    ...
    
    <table>
        <thead>
            <tr>
                <th>Id</th>
                <th>System name</th>
                <th>Task name</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <% if (Model == null || Model.Count() < 1) { %>
                <tr>        
                    <td colspan="4">
                        No Records found !! Please search.
                    </td>
                </tr>
            <% } else { %>
                <% foreach (var item in Model) { %>
                    <%= Html.Partial("_MyViewModel", item) %>
                <% } %>
            <% } %>
        </tbody>
    </table>
    

    Then we define a partial for the view model (~/Views/Home/_MyViewModel.ascx):

    <%@ Control 
        Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<AppName.Models.MyViewModel>" 
    %>
    <tr>
        <% using (Html.BeginForm("Update", "Home", FormMethod.Post, new { @class = "updateForm" })) { %>
            <td>
                <%= Html.DisplayFor(x => x.Id) %>
                <%= Html.HiddenFor(x => x.Id) %>
            </td>
            <td>
                <%= Html.EditorFor(x => x.SystemName) %>
                <%= Html.ValidationMessageFor(x => x.SystemName) %>
            </td>
            <td>
                <%= Html.EditorFor(x => x.TaskName) %>
                <%= Html.ValidationMessageFor(x => x.TaskName) %>
            </td>
            <td>
                <input type="submit" value="Update" />
            </td>
        <% } %>
    </tr>
    

    and the last part is to AJAXify those forms. This could be done unobtrusively in a separate javascript file using jquery:

    $(function() {
        $('.updateForm').submit(function () {
            var form = $(this);
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result) {
                    if (!result.success) {
                        form.closest('tr').replaceWith(result);
                    } else {
                        alert('record successfully updated');
                    }
                }
            });
            return false;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still very new to the MVC framework, but I managed to create
I'm very new to both the Mvc framework as well as JavaScript and JQuery.
I am new to ASP.NET and the MVC framework as well, so I'd love
Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring
I am fairly new at using the ASP.NET MVC framework and was hoping that
I'm rather new to MVC and as I'm getting into the whole framework more
I'm fairly new to the Zend Framework and MVC and I'm a bit confused
I'm pretty new to MVC 2 using the Entity Framework. I have two tables
I'm fairly new to Zend Framework and MVC in general so I'm looking for
I am setting up a simple routing system for my new custom MVC framework

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.