在部分视图中传递参数 - MVC3/Razor
如何将参数传递给 MVC3 (razor) 中的局部视图。我在 MVC 项目中用部分视图替换了常规视图页面。对于常规视图页面,我传递了像
public ActionResult MeanQ(int id)
{
Access access= db.Access.Find(id);
return View(access);
}
Now 这样的参数,因为我将视图更改为部分视图,所以我有以下代码:
public ActionResult MeanQ(int id)
{
Access access= db.Access.Find(id);
return PartialView("_MeanQPartial");
}
但不知道如何仍然传递参数“id”以使其像以前一样工作。请帮忙。就其价值而言, View 或部分 View 都由链接触发并显示在 Jquery 模态对话框中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
Try this
只需将其作为第二个参数即可。
PartialView
方法有 4 个重载,其中一个重载有两个参数PartialView(string viewName, object model)
View
将使用您的布局返回整个页面。PartialView
仅返回部分的 HTML。对于模态对话框,部分就足够了。无需检索完整页面。Simply give it as 2nd parameter.
PartialView
method has 4 overloads and this includes one with two parametersPartialView(string viewName, object model)
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.