2

I am trying to pass Eval to Html.RenderPartial inside ASP.NET Repeater but it does not work can any one help?

<asp:Repeater runat="server">
            <ItemTemplate>
                <% Html.RenderPartial("UserControl1",Eval("Title")); %>
            </ItemTemplate>
</asp:Repeater>

by the way I know that I can do it in other ways but I want to know if it is doable or not.

1
  • I know you can compbine WinForms with MVC... But man... I wouldn't recommend it. You're going to end up in a place you don't want to be. Maybe try putting your RenderPartial inside <%# %> statement. Jul 14, 2009 at 22:06

2 Answers 2

5
is the same as in that it expects an expression that returns a string, so to get this compiling you have to call a method that calls Html.RenderPartial(), then returns an empty string:
<%
protected string RenderControl(object dataItem) 
{
    Html.RenderPartial("UserControl1", ((MyType) dataItem).Title);
    return "";
}
%>

... <%# RenderControl(Container.DataItem) %> ...

I would just use foreach though - mixing WebForms data-binding and MVC partial rendering is unpredictable, at best:

<% foreach (MyObject o in data) { Html.RenderPartial("UserControl1", o.Title); } %>

Don't make life any harder than it needs to be...

1
  • Every thing is easy but <code><% Html.RenderPartial("UserControl1", o.Title);%></code> is making it hard it is different from other html extentions Thanks anyway Jul 15, 2009 at 15:04
0

Try putting your RenderPartial inside <%# %> statement like:

<asp:Repeater runat="server">
    <ItemTemplate>
        <%# Html.RenderPartial("UserControl1",Eval("Title")); %>
    </ItemTemplate>
</asp:Repeater>
1
  • Thanks for your help but I got this compilation exception: CS1026: ) expected I test it before it wont work thanks again... Jul 14, 2009 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.