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

  • Home
  • SEARCH
  • 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 7667205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:02:29+00:00 2026-05-31T15:02:29+00:00

I have a PaartialView declared like this: @model IEnumerable<mvc1.Models.ProjectDetailModel> @using (Html.BeginForm()) <form method=get action=EditProject

  • 0

I have a PaartialView declared like this:

@model IEnumerable<mvc1.Models.ProjectDetailModel>
@using (Html.BeginForm())         
<form method="get" action="EditProject" enctype="multipart/form-data">
<br />
<fieldset>
    <legend>Project Detail</legend>   
@foreach (var item in Model)
{
    <tr>
        <th class="thdetail">
            Project Code
        </th>
        <td class="tddetail">
            @Html.DisplayFor(modelItem => item.projectCode)
        </td>
        <tr>
        <th class="thdetail">
                Project Name
        </th>
        <td class="tddetail">
            @Html.DisplayFor(modelItem => item.projectName)
        </td>

        </tr>
        <tr>
            <th class="thdetail">
                Project Type
            </th>
            <td class="tddetail">
                @Html.DisplayFor(modelItem => item.projectType)
            </td>
        </tr>
        <tr>
            <th class="thdetail">
                Detailed Description
            </th>
            <td class="tddetail">
            <div style="height: 100px; width:700px; overflow: scroll">
                @Html.DisplayFor(modelItem => item.projectDescription)
            </div>
            </td>
        </tr>
    </table>
</fieldset>    
<input type="submit" value="Edit" /> 
</form>
}

On the submit button, i am calling a controller, but when it goes to the controller the model is not being passed back to the controller. How can i get the model back to the controller, or even just 1 field, ie. Model.projectCode which is the primary key

In the controller i have the fll which takes in the model and gets the primary key and calls a stored procedure to return results to another VIEW()

    [HttpGet]
    public ActionResult EditProject(ProjectDetailModel model)
    {
        DBController dbcontroller = new DBController();

        string l_user_name = SessionBag.Current.UserName;
        Int64 l_project_code = model.projectCode;

        if (dbcontroller.DBConnection())
        {
            MySqlCommand command = new MySqlCommand("edit_projects",   dbcontroller.conn);
            command.CommandType = System.Data.CommandType.StoredProcedure;

            // Input parameters for the insert_projects STORED PROC
            command.Parameters.Add(new MySqlParameter("userName",  SessionBag.Current.UserName));
            command.Parameters["@userName"].Direction =   System.Data.ParameterDirection.Input;
            // Output parameters for the view_sr_projects_detail STORED PROC               
            command.Parameters.Add(new MySqlParameter("projectName", MySqlDbType.LongText));
            command.Parameters["@projectName"].Direction = System.Data.ParameterDirection.Output;

            command.Parameters.Add(new MySqlParameter("projectType", MySqlDbType.LongText));
            command.Parameters["@projectType"].Direction = System.Data.ParameterDirection.Output;

            command.Parameters.Add(new MySqlParameter("projectDescription", MySqlDbType.LongText));
            command.Parameters["@projectDescription"].Direction = System.Data.ParameterDirection.Output;
           try
            {
                MySqlDataReader rdr = command.ExecuteReader();

                var model1 = new ProjectDetailModel();

                while (rdr.Read())
                {
                    model1.projectCode = (Int64)(rdr["projectCode"]);
                    model1.projectName = rdr["projectName"].ToString();
                    model1.projectType = rdr["projectType"].ToString();
                    model1.projectDescription = rdr["projectDescription"].ToString();
                }

                dbcontroller.conn.Close();

                return View(model1);
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                dbcontroller.conn.Close();

                ViewBag.Message = "Could not view your detail project. Error " + ex.Number + " has ocurred. Please try again or contact the system administrator.";
                return View("Error");
            }
        }
        else
        {
            ViewBag.Message = "Could not connect to the database. Please try again or contact the system administrator";
            return View("Error");
        }
    }        

My model looks like this:

public class ProjectDetailModel
{
    [Display(Name = "Project Code")]
    public Int64 projectCode { get; set; }

    [Display(Name = "User Name")]
    public string srUserName { get; set; }

    [Display(Name = "Project Name")]
    public string projectName { get; set; }

    [Display(Name = "Project Type")]
    public string projectType { get; set; }

    [Display(Name = "Project Requirement")]
    public string projectDescription { get; set; }
}

public class ProjectDetailModelList : List<ProjectDetailModel>
{
}

thanks
Naren

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

    Here this is what you can do. Below is just partial code, modify it to fit in with your example:

    Code in your view:

    <button id="btnEdit" type="button">Edit</button>
    

    I then use jQuery to add a click listener to the button (make sure that jQuery is added to the view):

    <script>
    
         $(document).ready(function () {
    
              $('#btnEdit').click(function () {
                   window.location = '@Url.RouteUrl(new { action = "EditProject", projectCode = Model.projectCode })';
              });
    
         });
    
    </script>
    

    Your action method:

    public ActionResult EditProject(int projectCode)
    {
         // Retrieve this specific project using this code
         // Do what needs to be done to populate the required input fields on view
    }
    

    This is the best way that I have found to do it.

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

Sidebar

Related Questions

If I have the below PartialView <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<Models.Photo> %> <% using (Html.BeginForm(MyAction,
I have called a view from another with Html.Action method. I want to call
I have controller method in my MVC application that I am calling using the
I have a PartialView strongly typed to a view model <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<VATRateManager_MVC.Models.ViewModels.RateControlEditViewModel>
I have this in my controller public ActionResult Testing() { CustomerContactModel model = new
I have a helper inside a partial that I am loading something like this:
I have a problem with Ajax.BeginForm. I have a form with submit and button
I have an Ajax.ActionLink inside a PartialView like so: @Ajax.ActionLink(Model.IsVisible ? Disable : Enable,
So I have this ascx (partialView) control - ControlTemp I have an ajax.BeginForm inside
I have an MVC action on my abstract BaseControlller like this (and this action

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.