Passing parameters in partial Views - MVC3/Razor

2019-06-18 05:20发布

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条回答
我只想做你的唯一
2楼-- · 2019-06-18 06:00

Try this

return PartialView("PartialViewName", access);
查看更多
Root(大扎)
3楼-- · 2019-06-18 06:00

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.

查看更多
登录 后发表回答