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
如何将参数传递给MVC3(razor)中的局部视图。我在我的MVC项目中用部分视图替换了常规的View页面。对于常规的View页面,我传递了类似的参数
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.
但我不知道如何仍然传递参数'id'以使其像以前一样工作。请帮忙。它的价值,视图或部分视图,都由链接触发并显示在Jquery模式对话框中。
2 个解决方案
#1
9
Try this
return PartialView("PartialViewName", access);
#2
5
Simply give it as 2nd parameter. PartialView
method has 4 overloads and this includes one with two parameters PartialView(string viewName, object model)
只需将其作为第二个参数。 PartialView方法有4个重载,这包括一个带有两个参数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.
它的价值,视图或部分视图,都由链接触发并显示在Jquery模式对话框中。
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.
View将使用您的布局返回整个页面。 PartialView仅返回部分HTML。对于模态对话框,局部就足够了。无需检索完整的页面。
#1
9
Try this
return PartialView("PartialViewName", access);
#2
5
Simply give it as 2nd parameter. PartialView
method has 4 overloads and this includes one with two parameters PartialView(string viewName, object model)
只需将其作为第二个参数。 PartialView方法有4个重载,这包括一个带有两个参数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.
它的价值,视图或部分视图,都由链接触发并显示在Jquery模式对话框中。
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.
View将使用您的布局返回整个页面。 PartialView仅返回部分HTML。对于模态对话框,局部就足够了。无需检索完整的页面。