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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:31:32+00:00 2026-05-15T07:31:32+00:00

I have a class that extends the HtmlHelper in MVC and allows me to

  • 0

I have a class that extends the HtmlHelper in MVC and allows me to use the builder pattern to construct special output e.g.

<%=
    Html.FieldBuilder<MyModel>(builder => {
        builder.Field(model => model.PropertyOne);
        builder.Field(model => model.PropertyTwo);
        builder.Field(model => model.PropertyThree);
    })
%>

Which outputs some application specific HTML, lets just say,

<ul>
    <li>PropertyOne: 12</li>
    <li>PropertyTwo: Test</li>
    <li>PropertyThree: true</li>
</ul>

What I would like to do, however, is add a new builder methid for defining some inline HTML without having to store is as a string. E.g. I’d like to do this.

<%
    Html.FieldBuilder<MyModel>(builder => {
        builder.Field(model => model.PropertyOne);
        builder.Field(model => model.PropertyTwo);
        builder.ActionField(model => %>
            Generated: <%=DateTime.Now.ToShortDate()%> (<a href="#">Refresh</a>)
        <%);
    }).Render();
%>

and generate this

<ul>
    <li>PropertyOne: 12</li>
    <li>PropertyTwo: Test</li>
    <li>Generated: 29/12/2008 <a href="#">Refresh</a></li>
</ul>

Essentially an ActionExpression that accepts a block of HTML. However to do this it seems I need to execute the expression but point the execution of the block to my own StringWriter and I am not sure how to do this. Can anyone advise?

  • 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-15T07:31:32+00:00Added an answer on May 15, 2026 at 7:31 am

    You only need to defer the execution of the action. Here’s an example:

    public static class HtmlExtensions
    {
        public static SomeClass ActionField<TModel>(this HtmlHelper<TModel> htmlHelper, Action<TModel> action)
        {
            return new SomeClass(() => { action(htmlHelper.ViewData.Model); });
        }
    }
    
    public class SomeClass
    {
        private readonly Action _renderer;
        public SomeClass(Action renderer)
        {
            _renderer = renderer;
        }
    
        public void Render()
        {
            _renderer();
        }
    }
    

    Which could be used like this:

    <% Html.ActionField(model => { %>
        Generated: <%=DateTime.Now.ToShortDate()%> (<a href="#">Refresh</a>)
    <% }).Render(); %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a base class such that public abstract class XMLSubscription <T extends
I have a few classes such that: public class XMLStatusMessage extends XMLMessage {} public
I have a class that I want to use to store properties for another
I have class that extends another class. class TWITTER_FOLLOWERS extends TWITTER_BOT in TWITTER_FOLLOWERS i
I have a class that extends Thread. This thread when running spends most of
I have a class that extends PDO to give it the ability to pull
I have a class that extends javax.swing.JPanel , it contains a single JButton. I've
I have a class that extends View. I override the onDraw method and allow
i have a class that extends the PDO class. it's called Database. but in
I am having a class that extends View. I have another class that extends

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.