1

What would this line of C# using Lambda expression be in VB.Net?

string s = blockRenderer.Capture(() => RenderPartialExtensions.RenderPartial(h, userControl, viewData));

Something with function of - but I can't figure out exactly how...

4 Answers 4

5

It should be something like this:

Dim s As String = blockRenderer.Capture(Function() RenderPartialExtensions.RenderPartial (h, userControl, viewData))
Sign up to request clarification or add additional context in comments.

Comments

3

Check out this online C# to VB.NET converter. It doesn't always get things perfect, but it does a pretty good job all the times I've used it.

Dim s As String = blockRenderer.Capture(Function() RenderPartialExtensions.RenderPartial(h, userControl, viewData))

Comments

1
Dim s As String = _
    blockRenderer.Capture( _
        Function() RenderPartialExtensions.RenderPartial(h, userControl, viewData) _
     )

Comments

1

Lambda Expressions in VB.NET need to have a return value, the solution is a wrapper method.

Public Shared Function RenderPartialToString(ByVal userControl As String, ByVal viewData As Object, ByVal tempData As Object, ByVal controllerContext As ControllerContext) As String

        Dim h As New HtmlHelper(New ViewContext(controllerContext, New WebFormView("omg"), viewData, tempData), New ViewPage())
        Dim blockRenderer As New MvcContrib.UI.BlockRenderer(controllerContext.HttpContext)
        Dim s = blockRenderer.Capture(New Action(Function() renderPartialLambda(h, userControl, viewData)))

        Return s

End Function





Private Shared Function renderPartialLambda(ByVal html As HtmlHelper, ByVal userControl As String, ByVal viewData As Object)
                RenderPartialExtensions.RenderPartial(html, userControl, viewData)
                Return Nothing
End Function

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.