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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:33:08+00:00 2026-05-29T09:33:08+00:00

I have a helper called EditableArea which provides a user with a runtime-editable div

  • 0

I have a helper called EditableArea which provides a user with a runtime-editable div (via JS). EditableArea helper checks if an editable area (not related to MVC’s Area) with the specified ID exists in the DB, if so then it renders the area’s HTML, otherwise it displays the default markup specified as a parameter of the helper:

@Html.EditableArea(someId, "<p>Click to edit contents</p>")

It all works ok, but I’d like to change it so that the default markup is specified not as a string but in razor syntax, something like:

@using (Html.EditableArea(someId))
{
    <p>Click to edit contents</p>
}

Or something similar, like the way @sections work in MVC3.

How can I achieve that?

I can make an IDisposable which in its Dispose closes the TagBuilder, etc., but using this approach the markup will still be rendered (I can clear the rendered contents in the Dispose() but the code block would still run unnecessarily, which I’d like to avoid).

Is there some other way to pass a razor block to the helper, which may or may not be actually rendered?

  • 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-29T09:33:09+00:00Added an answer on May 29, 2026 at 9:33 am

    Here’s an example I use to render jQuery Template markup by passing in a template Id and razor-style syntax for the template itself:

    public static MvcHtmlString jQueryTmpl(this HtmlHelper htmlHelper, 
        string templateId, Func<object, HelperResult> template) 
    {
        return MvcHtmlString.Create("<script id=\"" + templateId + 
            "\" type=\"x-jquery-tmpl\">" + template.Invoke(null) + "</script>");
    }
    

    and this would be called with

    @Html.jQueryTmpl("templateId", @<text>any type of valid razor syntax here</text>)
    

    Basically just use Func<object, HelperResult> as your parameter and template.Invoke(null) (with arguments if necessary) to render it. Obviously you can skip the call to .Invoke() to avoid rendering the “default” markup.

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

Sidebar

Related Questions

I created Area called Admin. I have Custom Helper in the root folder called
I have a dll called utilities which contains some helper methods and I want
I have a helper called user_order which returns an instance of Order . Order
I have helper class which contain different methods. I dо not want to include
I have a helper function, which basically calls CompareTo on two objects, but does
I have a helper assembly which includes a function to identify object types: namespace
I have defined a function called is_logged_in? in a user defined library stored in
Suppose I have Objective C interface SomeClass which has a class method called someMethod
we have model helper (used by several different models) called set_guids that sets self.theguid
I have a helper method which encrypts some data on the iPhone. If the

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.