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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:35:44+00:00 2026-05-24T05:35:44+00:00

I guess what I want to do is chain my data down so that

  • 0

I guess what I want to do is “chain” my data down so that it ends up looking the same.
All my html must be wrapped in some form of

<fieldset class="" data-role="">

So what I have is a helper that prints the various forms. One would be a label:

<fieldset data-role="@role">
    <label>@Html.Raw(label)</label>
</fieldset>

Now when I have multiple types of labels, and one includes being a code block. When it is a
simple piece of text, like “First Name” I do:

@FieldSet.Label("First Name")

But when I have a code block such as:

<b>some text</b>
<p>some other text (some time frame - some time frame)

It becomes complicated to use this:

@FieldSet.Label("<b>" + Model.Text1 + "</b><p>" + Model.Text2 + 
    " (" + Model.Time1 + " - " + Model.Time2 +")</p>")

What I want it a solution that looks something like this:

@FieldSet.Label(@<text>
<b>@Model1.Text1</b>
<p>@Model.Text2 (@Model.Time1 - @Model.Time2)</p>
</text>)

I read somewhere this was possible, but I cannot find the article. I could be completely misled, but I really don’t want to have a single piece of HTML in the code behind and I want to utilize the razor syntax, not string concatenation.

  • 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-24T05:35:45+00:00Added an answer on May 24, 2026 at 5:35 am

    Check this articles from Phil Haack

    • http://haacked.com/archive/2011/02/27/templated-razor-delegates.aspx
    • http://haacked.com/archive/2011/04/14/a-better-razor-foreach-loop.aspx

    You could:

    Write as an extension method to a strongly-typed HtmlHelper:

    public static class RazorExtensions
    {
        public static HelperResult Label<T>(this HtmlHelper<T> helper, Func<T, HelperResult> template) {
            return new HelperResult(writer => {
                writer.Write("<label>");
                template(helper.ViewData.Model).WriteTo(writer);
                writer.Write("</label>");
            });
        }
    }
    

    So you could write

    @Html.Label(@<text><span>@Model.Item1<span><strong>@Model.Item2</strong></text>)
    

    Pass Model as a parameter to your helper method

    public static class FieldSet
    {
        public static HelperResult Label<T>(this T model, Func<T, HelperResult> template) {
            return new HelperResult(writer => {
                writer.Write("<label>");
                template(model).WriteTo(writer);
                writer.Write("</label>");
            });
        }
    }
    

    Usage:

    @FieldSet.Label(Model, @<div><span>@Model.UserName</span><strong>@Model.FullName</strong><p>@Model.Description</p></div>)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a solution for tag:hover that is not working on ie6. My guess
This is very basic magento question i guess. I want to first get all
Yes, as you might guess, I want to ask about Cloud-computing. I doubt that
I guess I want to ultimately build out a script that will force the
I am working on a Google Gadget that will collect some data through Google
Say you want to take CMU's phonetic data set input that looks like this:
Everytime the user makes a wrong guess I want the label7.text to display that
I want to be able to give a best guess for what city and
Simple question I guess, I want to use PHP to write an update to
I don't want to open another Yet Another Js VS Js thread. I guess,

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.