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 6824159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:52:07+00:00 2026-05-26T21:52:07+00:00

What I am trying to do is to be able to write javascript blended

  • 0

What I am trying to do is to be able to write javascript blended with razor styled markup and methods inside .cshtml file and send this to a separate method for usage later on.

My .cshtml looks something like this:

@{SomeClass.SaveForLater(@<script type="text/javascript">window.alert('@Model.SomeParamter')}</script>);

And inside the class SomeClass:

public static void SaveForLater(HtmlString str) {
    // will be using str.ToString() here and save the string output for use later on.
}

But what I receive is this error message:
CS1660: Cannot convert lambda expression to type ‘System.Web.HtmlString’ because it is not a delegate type

Am I using the wrong type for the argument or do I need to rethink the whole concept?

Solution
Thanks to SLaks below I ended up doing this:

public static void SaveForLater<T>(Func<T, HelperResult> template, dynamic model)
{
    // template(model).ToHtmlString()
}

Using it like this:

 @{SomeClass.SaveForLater<SomeModel>(
        @<script type="text/javascript">window.alert('@Model.SomeParamter')</script>,
        Model
        );
  • 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-26T21:52:08+00:00Added an answer on May 26, 2026 at 9:52 pm

    You’re trying to take an inline helper.
    You need to accept a Func<Something, HelperResult>.

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

Sidebar

Related Questions

I'm trying to write a javascript regexp for a blacklist of file extensions. I'm
I'm trying to get JavaScript to read/write to a PostgreSQL database. I found this
I'm trying to write a function that is able to determine whether a string
I'm trying to be able to write an extensible grammar using functions, but can't
I am trying to write separate logs for different packages using log4j. I am
I'm trying to write a Javascript regexp replace function that allows me to replace
I am trying to write my own Javascript Framework something like jQuery. I use
I am trying to write a javascript function to resize an image based on
I'm developing a Bitbucket API wrapper in JavaScript. I'm trying to write tests for
I am trying to write some javascript to allow me to click on a

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.