开发者

Passing parameters in partial Views - MVC3/Razor

开发者 https://www.devze.com 2023-03-12 06:23 出处:网络
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

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 开发者_如何学Pythonpartial View , both are triggered by a link and displayed in a Jquery Modal Dialog box.


Try this

return PartialView("PartialViewName", access);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消