6

How can I pass parameters to a partial view in MVC3 (razor). I replaced a regular View page with a Partial View in my MVC project. For a regular View page, I passed parameters like

   public ActionResult MeanQ(int id)
    {            
        Access access= db.Access.Find(id);
        return View(access);
    }

Now since I changed the view to a partial view, I have the following code instead:

  public ActionResult MeanQ(int id)
    {            
        Access access= db.Access.Find(id);
        return PartialView("_MeanQPartial");
    }

but do not know how I can still pass the parameter 'id' to make it work like before. Please help. For what its worth, the View or the partial View , both are triggered by a link and displayed in a Jquery Modal Dialog box.

2 Answers 2

9

Try this

return PartialView("PartialViewName", access);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you... I thought I tried that and it didnt work.. but it works now. I didnt test properly I think. Appreciate your help ..
5

Simply give it as 2nd parameter. PartialView method has 4 overloads and this includes one with two parameters PartialView(string viewName, object model)

public ActionResult MeanQ(int id)
{            
    Access access= db.Access.Find(id);
    return PartialView("_MeanQPartial", access);
}

For what its worth, the View or the partial View , both are triggered by a link and displayed in a Jquery Modal Dialog box.

View would return an entire page using your layout. PartialView only returns the HTML from your partial. For a modal dialog, the partial is enough. No need to retrieve a complete page.

Comments

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.