Using RenderAction(actionname, values) in MVC4 issue

后端 未结 2 1676
醉酒成梦
醉酒成梦 2020-12-30 23:43

I need to display some child objects (Items) of an entity Request. Instead of Request I found it better to pass in a view that contains more info t

相关标签:
2条回答
  • 2020-12-31 00:23

    Usefully alternative:

    @model CAPS.RequestInfo
    ...    
    @Html.Action("Items", new { requestId = Model.Id })
    

    This code returns MvcHtmlString. Works with partialview and view result. Doesn't require {} chars.

    0 讨论(0)
  • 2020-12-31 00:31

    You need to use this syntax when calling the Render methods:

    @{ Html.RenderAction("Items", new { requestId = Model.Id }); }
    

    The @syntax, without the curly braces, expects a return type which gets rendered to the page. In order to call a method that returns void from the page, you must wrap the call in curly braces.

    Please see the following link for a more in-depth explanation.

    http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx

    0 讨论(0)
提交回复
热议问题