'Getting the Object reference not set to an instance of an object exception in ASP.NET Core MVC

I'm trying to connect an object from one View to another. I have a user action history where I have all of my CRUD operations listed. I'm trying to add an action link that when I go to my action history the name of the object that was created/updated/deleted(soft delete), becomes a link that will redirect me to the Edit view of that object. I tried via. @Html.ActionLink like this:

@Html.ActionLink(item.PreduzvePibfkNavigation.NazivPreduzeca, "IzmenaPreduzeca","Preduzece", new {Id = item.PreduzvePibfk}, null)

This is my controller for the 'IzmenaPreduzeca' action:

        [HttpGet]
        public IActionResult IzmenaPreduzeca(int id)
        {
            Preduzece preduzece = _preduzece.getById(id);
            ViewBag.izabrani = preduzece.NazivPreduzeca;
            return View(preduzece);
        }

        [HttpPost]
        public IActionResult IzmenaPreduzeca(Preduzece preduzece, IstorijaPromena istorijaPromena, string razlog)
        {
            try
            {
                _preduzece.Update(preduzece);
                _preduzece.IstorijaPromene(preduzece, istorijaPromena, CrudType.Update, DateTime.Now, "Branislav Zivanovic", razlog);
                _preduzece.SaveToDb();

                return RedirectToAction("PregledPreduzeca");
            }
            catch (Exception ex)
            {
                return NotFound($"Error, details: {ex.Message}");
            }
        }

I don't understand why do I get this error

Object reference not set to an instance of an object

Is there another way?

This is the user action history:

Image of the user action history



Solution 1:[1]

input parameter id is always 0, fix the action header

[HttpGet("{id}")]
public IActionResult IzmenaPreduzeca(int id)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1