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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:14:05+00:00 2026-05-29T12:14:05+00:00

I make one action method for 2 activities (new input and edit), and there

  • 0

I make one action method for 2 activities (new input and edit), and there is also only one
view to handle those activities.
But I don’t understand no matter what activity happen, the action method always think it is a new input.
I learned that it because of the ID is always 0, but the problem is, when doing the edit, when in the view the ID is correct as the ID of the data, but when I click the submit button, the action method just see the 0 value of ID.

Here is the action method I used:

[HttpPost]
public ActionResult AddAssignment(SateliteSchedule SatSched)
{
    var txt = "";

    if (ModelState.IsValid)
    {
        if (SatSched.ID == 0)
        {
            db.SateliteSchedules.Add(SatSched);
            txt = "{0} has been added!";
        }
        else
        {
            db.Entry(SatSched).State = EntityState.Modified;
            txt = "{0} has been modified!";
        }

        db.SaveChanges();

        Utility utl = new Utility();
        TempData["message"] = string.Format(txt, utl.GetSateliteName(SatSched.SateliteID));

        return RedirectToAction("FormAssignment");
    }
    else
    {
        ViewBag.Message = "ModelState is not Valid!";

        return View("ErrorView");
    }
}

And here is the view:

@using (Html.BeginForm("AddAssignment", "admin", FormMethod.Post))
{
    @Html.ValidationSummary(true)

   <table>
     <tr>
       <td>@Html.LabelFor(m => m.Tanggal)
       </td>
       <td>
           @Html.EditorFor(m => m.Tanggal)
           @Html.ValidationMessageFor(m => m.Tanggal)
       </td>
     </tr>
     <tr>
       <td>@Html.LabelFor(m => m.SateliteID)</td>
       <td>
            @Html.DropDownList("SateliteID", (IEnumerable<SelectListItem>)ViewBag.SatList, "--- Satelite ---")
            @Html.ValidationMessageFor(m => m.SateliteID)
       </td>
     </tr>
     <tr>
       <td>@Html.LabelFor(m => m.WMOnDuty)</td>
       <td>
           @Html.DropDownList("WMOnDuty", (IEnumerable<SelectListItem>)ViewBag.WMList, "--- Worship Manager ---")
           @Html.ValidationMessageFor(m => m.WMOnDuty)
       </td>
     </tr>
     <tr>
       <td>@Html.LabelFor(m => m.SMOnDuty)</td>
       <td>@Html.EditorFor(m => m.SMOnDuty)</td>
     </tr>
     <tr>
       <td>@Html.LabelFor(m => m.WLOnDuty)</td>
       <td>@Html.EditorFor(m => m.WLOnDuty)</td>
     </tr>
     <tr>
       <td>@Html.LabelFor(m => m.MLOnDuty)</td>
       <td>@Html.EditorFor(m => m.MLOnDuty)</td>
     </tr>
     <tr>
       <td>@Html.LabelFor(m => m.SoundMan)</td>
       <td>@Html.EditorFor(m => m.SoundMan)</td>
     </tr>
     <tr>
       <td valign=top>@Html.LabelFor(m => m.Note)</td>
       <td>@Html.TextAreaFor(model => model.Note, new { @class = "memo-text" })</td>
     </tr>
   </table>
    <div>
       <input type="submit" value="Save" />
       @Html.ActionLink("Kembali", "FormAssignment")
    </div>
}

What should I check to fix this?

  • 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-29T12:14:07+00:00Added an answer on May 29, 2026 at 12:14 pm

    You have to have the Id as a hidden, so when you go in the method the model will have the id asigned to it (does it make sense?). try placing this in your form

    @Html.HiddenFor(m => m.ID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to make a show action of one of my controllers the root.
I am in one action on Rails, but I wish to continue processing from
I have an action method that takes in a string as its only parameter.
Is it quicker to make one trip to the database and bring back 3000+
How do I make one jquery ui slider control another? If I slide slider
I need to make one function in a module platform-independent by offering several implementations,
This question might make one smile, really, HDD space is as cheap as dirt
While trying to make one of my python applications a bit more robust in
I want to make one website for all PC, IPhone, Blackberry, Windows Mobile (IE
How can we make one database restore date to date, like sunday to wednesday

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.