0

So, these are the 2 pieces of code that are causing the error.

The View:

...
@foreach (FinalCampaign fc in @Model)
{
   <h1>@fc.Camp.Id</h1>
   <h2>@Html.ActionLink(@fc.Camp.Name, "GoToPage", "Home", fc.Camp.Id, null)</h2>
   <p>@fc.Camp.CampaignStartDate - <font color="Blue"><u>@fc.Username</u></font></p>
   <p>@fc.Camp.Description</p>
}

And here is the "GotoPage" function from my controller:

public ActionResult GoToPage(string id)
    {
        CampaignCommentsModel ff = new CampaignCommentsModel();
        var cT = new CampaignTable(new OracleDatabase("DefaultConnection"));
        Campaign camp = cT.GetCampaignById(id);
        ...
        return View(ff);
    }

And this is my problem: the "id" from GotoPage (the argument) is null, it doesn't receive the value from my view.

Lerul Ler
  • 339
  • 7
  • 21
  • you're using [this overload](https://msdn.microsoft.com/en-us/library/dd504972(v=vs.118).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2). Take a look at the example on the page and adjust your routeValues to look like it – Jonesopolis May 26 '15 at 13:28

2 Answers2

2

You should use:

 <h2>@Html.ActionLink(@fc.Camp.Name, "GoToPage", "Home", new { id = fc.Camp.Id}, null)</h2>

You can not pass a nested properties in this way. The default model binder can not associate such an object with a parameter in your action method.

ActionLink extension: https://msdn.microsoft.com/en-us/library/dd492124(v=vs.118).aspx

Model binding: What is model binding in ASP.NET MVC?

Community
  • 1
  • 1
Pawel Maga
  • 5,428
  • 3
  • 38
  • 62
0
<h2>@Html.ActionLink(@fc.Camp.Name, "GoToPage", "Home",new {id = fc.Camp.Id}, null)</h2>

See here Actionlink method

Amit Kumar
  • 5,888
  • 11
  • 47
  • 85