Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 232409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:00:54+00:00 2026-05-11T20:00:54+00:00

I need to render a partialview to a string, and I am trying to

  • 0

I need to render a partialview to a string, and I am trying to convert a C# example to VB.Net, as I am stuck with that for this project.

This is causing me a headache from these two problems:

  1. ObjectViewData – I can’t figure out what that is
  2. RenderPartial is a sub, but seems to be used as a function – I don’ get it

I reference the MVCContrib.UI, so I don’t need to convert that. But these two functions, I do need to convert:

(from brightmix.com)

/// Static Method to render string - put somewhere of your choosing
public static string RenderPartialToString(string userControl, object viewData, ControllerContext controllerContext)
{
    HtmlHelper h = new HtmlHelper(new ViewContext(controllerContext, new WebFormView("omg"), null, null), new ViewPage());
     var blockRenderer = new BlockRenderer(controllerContext.HttpContext);

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

     return s;
 }

 /// Your Controller method...  
 public ActionResult MakeStringForMe()
 {
     var objectViewData = new objectViewData { SomeString = "Dude", SomeNumber = 1 };

     string s = RenderPartialToString("~/Views/Controls/UserControl.ascx", objectViewData, this.ControllerContext);

     View();
 }

Here is my attempt at converting it to VB.Net

'Static Method to render string - put somewhere of your choosing'
Public Shared Function RenderPartialToString(ByVal userControl As String, ByVal viewData As Object, ByVal controllerContext As ControllerContext) As String

    Dim h As New HtmlHelper(New ViewContext(controllerContext, New WebFormView("omg"), Nothing, Nothing), New ViewPage())

    Dim blockRenderer As New MvcContrib.UI.BlockRenderer(controllerContext.HttpContext)

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

End Function

Public Function MakeStringForMe() As ActionResult

    Dim objectViewData As objectViewData = New objectViewData With {.SomeString = "Dude", .SomeNumber = 1}
    Dim s As String = RenderPartialToString("~/Views/Controls/UserControl.ascx", objectViewData, Me.ControllerContext)
    View()
End Function

alt text

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:00:54+00:00Added an answer on May 11, 2026 at 8:00 pm

    This line:

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

    is NOT equivalent to your original line:

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

    The C# example is using a lambda, while the VB example is just calling the method directly, which doesn’t return a value. The compiler isn’t lying to you.

    Try this instead:

    Dim s = blockRender.Capture(New Action(Of String)(Function() RenderPartialExtensions.RenderPartial(h, UserControl, viewData)))
    

    I took a look at Capture and it’s expecting an Action which is just a delegate, and it looks like the compiler can’t infer the delegate’s signature to wrap the anonymous function. So we’ll give it a helping hand and wrap the lambda ourselves.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use URI routing to override the default controller/function/arguments mapping. Example:… May 11, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer You can determine the status of the fulltext indexing by… May 11, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer If you mean a python script, just do something like… May 11, 2026 at 11:33 pm

Related Questions

I need to render a list of Person objects, say, in a comma delimited
Hopefully this example will illustrate my point better than simply trying to explain it:
I need to change the way MVC is rendering action links(and form's and url's,
I am looking for a way to display TIF documents on a web page.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.