- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我需要显示实体 Request
的一些子对象 (Items
)。我发现传递包含比原始请求实体更多信息的 View 而不是请求。我将此 View 称为 RequestInfo
,它还包含原始请求 Id
。
然后在 MVC View 中我做了:
@model CAPS.RequestInfo
...
@Html.RenderAction("Items", new { requestId = Model.Id })
渲染:
public PartialViewResult Items(int requestId)
{
using (var db = new DbContext())
{
var items = db.Items.Where(x => x.Request.Id == requestId);
return PartialView("_Items", items);
}
}
这将显示一个通用列表:
@model IEnumerable<CAPS.Item>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Code)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.Qty)
</th>
<th>
@Html.DisplayNameFor(model => model.Value)
</th>
<th>
@Html.DisplayNameFor(model => model.Type)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Code)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.Qty)
</td>
<td>
@Html.DisplayFor(modelItem => item.Value)
</td>
<td>
@Html.DisplayFor(modelItem => item.Type)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
但是我在 RenderAction
行 "Cannot implicity convert type 'void' to 'object'" 有什么想法吗?
最佳答案
调用 Render 方法时需要使用此语法:
@{ Html.RenderAction("Items", new { requestId = Model.Id }); }
没有大括号的@syntax
需要一个呈现给页面的返回类型。为了从页面调用返回 void 的方法,您必须将调用用花括号括起来。
请参阅以下链接以获得更深入的解释。
http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx
关于c# - 在 MVC4 问题中使用 RenderAction(actionname, values),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14157072/
我有一个 div 可以在我的页面上呈现图片库 @{ Html.RenderAction("UserGallery"); } 我有这个函数
为什么这段代码是正确的: @{ Html.RenderAction("PostImagesForPost", "BlogPost", new { id = Model.ID }); } 还
我的 Controller 中有 [ChildActionOnly],名为 _AllLinks 如果 _AllLinks.cshtml 在我的 Controller 目录中,我可以使用 RenderA
我的设置: 查看一条路线,如:/Pages/Details/2 页面详情 View 有呈现评论表单 评论表单发布到 Comments/CreatePageComment /Comments/Creat
我对 RenderAction() 函数的作用感到满意。但是,我想在部分渲染的操作中对数据的加载和存储进行ajaxify,以便一切都发生在一个页面中。 想象一下以下情况:我有一个文章详细信息 View
您好,我想知道 mvc C#s 渲染操作是否与直接在我的评论中调用部分一样有效,如果不是,那么效率有多低。 最佳答案 RenderAction 肯定会比 RenderPartial 慢。差异将取决于您
如何将一个类应用于以下对象,以便我可以对其应用特定的 css 样式? 其余部分由 anchor 标记组成,因此我可以轻松应用一个类,但是我应该将它粘贴到这个@Html.RenderAction 的什么
是否可以使用 HTMl.RenderAction 使用 ajax 提供参数? 我有一个这样的 Controller 操作 [ChildActionOnly] Public ActionResult E
当我的 View 显示 RenderAction 时,我在 Fiddler 中没有看到任何额外的请求调用。是不是因为它不是一个单独的 Web 请求,也就是说,它是在 Controller 呈现其 Vi
我有一个包含 (c => c.SidebarStats()); %> 的 ViewPage .在操作 SidebarStats 的 Controller 操作上,我有一个 OutputCache 操作
我正在扩展 htmlhelper。但我不能调用它的渲染 Action 。 using System.Text; using System.Web.Mvc; using System.Web.Mv
我正在创建一个使用区域的 ASP.NET MVC 2 (RTM) 项目。一个区域的Home Controller 的Index Action 需要使用RenderAction来生成页面的一个子区域。调
我有一个 PartialViewResult 操作,它呈现一个我从页面上的 $.ajax 调用调用的 PartialView。 该 PartialView 对于 VM 中的项目也有一个 foreach
我正在尝试在 Controller 操作中使用 Route 属性命名(例如:[Route(Name = "Abc123")]),并且同样能够通过 Html 调用它.RenderAction,但是貌似这
我正在阅读一本使用旧版本 Html.RenderAction 的 MVC 书籍.所以书上是这样的Html.RenderAction("Summary", "Cart");我不得不转换为 Html.Re
在我安装 ASP.NET MVC 1.0 RTM 之前,调用工作正常。 错误:CS0121:调用在以下方法或属性之间不明确 代码片段 操作方法 public ActionResult Product
我在 *.cshtml 文件中有一个 javascript $(function () { sliderDiv.slider({ range: true, min: minVal, max
我在将 CaSTLe Windsor Controller Factory 与新的 RenderAction 方法结合使用时遇到了问题。我收到以下错误消息: Controller “MyControl
我将 MVC 添加到我现有的 webforms 项目中。除了 RenderAction 正在寻找 .aspx 文件之外,一切都很顺利 The view '_Mainmenu.cshtml' or it
根据 Brad Wilson 的说法,RenderAction 比 RenderPartial 慢。 但是,有没有人得到任何显示性能差异的统计数据? 我正在开发一个应用程序,其中页面由“小部件”组成。
我是一名优秀的程序员,十分优秀!