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

  • Home
  • SEARCH
  • 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 8252769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:38:40+00:00 2026-06-08T00:38:40+00:00

I read this very helpful post: how to render html to a string instead

  • 0

I read this very helpful post: how to render html to a string instead of to the screen in MVC3.

I’ve created a function that does just that in my controller. I would now like to be able to call this method from class in another project so that I can offer this function as a service. The code looks like this:

 using (var sw = new StringWriter())
        {
            var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
            var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
            viewResult.View.Render(viewContext, sw);
            viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
            return sw.GetStringBuilder().ToString();
        }

I’d like to call this class directly and not via the IIS. But then the ControllerContext is null. Can I specify the View on disc somehow?

  • 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-06-08T00:38:42+00:00Added an answer on June 8, 2026 at 12:38 am

    http://msdn.microsoft.com/en-us/library/system.web.mvc.viewengineresult(v=vs.108)

    You can create the ViewEngineResult by providing list of locations instead of calling FindPartialView

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

Sidebar

Related Questions

This is a very basic question on Java. I've read somewhere that at first
This is not a biggie at all, but something that would be very helpful
has anyone ever read/skimmed through this book? it is valuable/very helpful to people such
I've read this article, Using reCAPTCHA with Google App Engine , it wasn't very
I read this post where the author advices to store session files in a
I read this article : http://lwuit.blogspot.in/2008/06/lightweight-text-input-in-lwuit.html This article talks of autocomplete textfield embedded on
I have read this thread FATAL EXCEPTION main Android App and it is very
I don't even know where to go with this. Google wasn't very helpful. As
I read this question in stackoverflow. The excerpt answer provided by bbum is below:
I read this code in a library which is used to display a bitmap

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.