Search code examples
c#asp.net-mvchtml.actionlink

Html.Action passing value from model returns null


I'm trying to pass a value into an Html.Action using FirstOrDefault to return the first entry in an array of values. The value is not picked up and I keep getting a null exception.

The family variable picks up the correct values from the model as a key/value pair.

What do I need to do to pass the zero indexed Value "2" as the parameter in the Action?

Code and debug information:

VisualStudio

----Edit for Code---

Family Index Action

    public ActionResult Index(int familyId)
    {            
        var model = GetDisplay(familyId).OrderByDescending(i => i.dob);
        return PartialView(model);
    }

Family ViewModel

public partial class FamilyListViewModel
{
    public int Id { get; set; }
    public int familyId { get; set; }
    public string name { get; set; }
    ...
}

Solution

  • This is actually a Dictionnary, you have to retrieve the value of your key like this :

    @Html.Action("Index", "Family", new { familyId = family["Id"] })
    

    Hope it helps !