Passing Parameters in Partial View - MVC3 / Razor

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

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

Now that I have 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 I don’t know how I can pass the 'id' parameter so that it works as before. Please help. For what is a View or a partial view, both are launched by reference and displayed in the JQuery Modal dialog box.

+6
source share
2 answers

try it

 return PartialView("PartialViewName", access); 
+9
source

Just specify it as the 2nd parameter. PartialView has 4 overloads and 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 is a View or a partial view, both are launched by reference and displayed in the JQuery Modal dialog box.

View will return the whole page using your layout. PartialView returns only HTML from partial. Partial for a modal dialogue. No need to retrieve the full page.

+5
source

Source: https://habr.com/ru/post/890160/


All Articles