0

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; }
    ...
}
3
  • We can't see your code. Commented Sep 30, 2013 at 13:05
  • 1
    Looking at that, why don't you just pass family since it's already a RouteValueDictionary which is what one of the overloads of Action() expects? Commented Sep 30, 2013 at 13:06
  • @ChrisHardie I've added the ViewModel and the Index action. Commented Sep 30, 2013 at 13:20

2 Answers 2

1

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 !

Sign up to request clarification or add additional context in comments.

5 Comments

this still returns null
family["Id"] returns null ?
this still returns null, yes.
The Action is looking for familyId, not id.
Good spot Jim - can't see the wood for the trees sometimes. The above works now Joffrey, thanks.
1

Try with the below code and send the familyId parameter as expected by your action

@Html.Action("Index", "Family", new{familyId= Model.familyId })

1 Comment

this still returns null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.