Creating Markup Actions in Razor

Razor’s inline helpers allow you to create lambda expression that return markup (as a HelperResult).  However, there is no simple way to create a lambda expression that writes HTML directly to the page (instead of returning it).

In ASPX pages, one can simply put the beginning and end of a lambda expression in expression blocks, then put markup in the middle.

For example, this code creates a delegate that writes a <b> tag to the page:

    Action pageWriter = () => {%><b>I'm from a lambda!</b><%};

Calling the pageWriter delegate will write directly to the HTTP response stream.

By contrast, Razor inline expressions return their markup.  To do this in a Razor page, one would write

    Func<object, HelperResult> htmlMaker
         = @<b>I'm from a lambda!</b>;
    @htmlMaker(null)    //Note @ sign
    @htmlMaker(null)    //Note @ sign
    @htmlMaker(null)    //Note @ sign

Calling htmlMaker without an @ sign will return HTML, but won’t write anything to the page.

When working with libraries designed for ASPX pages, it can be necessary to create ASPX-style inline helpers that write to the page instead of returning a value.  You can do that by creating an inline helper lambda and passing it to the Write method:

    Action pageWriter = () => Write(new Func<object, HelperResult>(
         @<b>I'm from a lambda!</b>


Like the ASPX version, pageWriter now writes directly to the page and does not return anything.

This code can be made simpler by wrapping it in a separate method:

Action MakeAction(Func<object, HelperResult> inlineHelper) {
    return () => Write(inlineHelper(null));

This method takes an inline helper and returns an Action that writes the helper’s output to the page.  Since it needs to call the page’s Write method (to use the page’s output stream), this method must be defined in the WebPageBase instance, either in an @functions block or in a common base class.

Any code in the inline helper will execute each time the resulting Action is called.

It can be called like this:

    Action pageWriter2 = MakeAction(@<b>I'm from a lambda!</b>);


This code is equivalent to the previous sample, but it’s much simpler.

One can also write write a version that takes a parameter:

Action<T> MakeAction<T>(Func<T, HelperResult> inlineHelper) {
    return param => Write(inlineHelper(param));
Note that the type parameter must be specified explicitly; C# does not infer type parameters from the method’s return type.


Thanks for this information. I found it very useful in coming up with my own solution.

Just to explain what I wanted to do, I wanted to pass around markup just as you would pass around variables of any other type. However, sometimes when you use variables within a markup block and that variable changes (for example during a for-loop), it prints the last value that the variable was assigned (as opposed to the value it held at the time).

Therefore what I did was to strictly evaluate the markup passed in.

The following is my solution:

HtmlString Markup(Func<dynamic, HelperResult> markupExpr)
return new HtmlString(markupExpr(null).ToHtmlString());

and you can call it as such:

var markup = Markup(@<span>...</span>);

(at this point you can put it in a list etc).

and then you can call it:


Nice and useful info. Thanks


I recommend you to have a look here if you are bored. It will help you to make homework fun.

Thank you for sharing excellent information. Your website is so cool. I am impressed by the details that you have on this website.

I am very happy after reading this fantastic Article, I appereciate your work. |

Sign in to enter office setup product key. Know how to benefit, download, install, set in movement, uninstall and reinstall MS office setup.
call us at +1-888-421-9666[tool free]

If you can’t remember the account that you used, support might be able to help. Get Support; Do you have an Webroot Key code? Enter your product key; Don’t have Webroot yet? If you don’t have Webroot, you can try or buy it in the Buy now option. If you have an webroot subscription, on your safe page

Electricity is the set of physical phenomena associated with the presence and motion of matter that has a property of electric charge. In early days, electricity was considered as being unrelated to magnetism. Later on, many experimental results and the development of Maxwell's equations indicated that both electricity and magnetism are from a single phenomenon

what is electricity

Microsoft with your product key. Get started: step 1. Go to - Sign in,
2nd. Enter product key, and 3rd. Install Office 365 or Office 2016. If you are having any Office Setup issue then call us at 24*7 for technical help. we also help with like Excel, PowerPoint, PowerPoint,
Word, OneNote, ...all type issue ..We are also handing more lots of product
California zip@code 90002 ||

We are available 24/7 to help you out the complete procedure of download and install of And also Check out here complete steps for for downloading, installing, uninstalling, and activating, and also get antivirus help for For norton activation, get the 25 characters alphanumeric product key from Norton offers hordes of reliable antivirus programs gadgets that are enabled to access internet are vulnerable to online threats as long as they don’t have any antivirus program installed to protect them against viruses and malware. No matter if you are a business person, freelancer, household, or an employee, Norton provides high-end security infrastructure to every user. Make sure to only purchase the right product that matches your security obligations. As Norton offers you a trial version of every product online without implying any charges, you can easily get to know their performances before paying for the subscription plan. You can get the details and access the trial version via

We are providing online assistance to the customers for norton antivirus. If you want support from the expert's so, you can click on the following link and our expert's give you the best solution to your problem.

To get support for Download, Install MS Office on your computer, you can visit the official website of MS Office or click on the following link to open the official website of MS Office.

Microsoft Excel is a spreadsheet developed by Microsoft for Windows, macOS, Android and iOS.
If your Microsoft Excel 2010 Crashes so, here are some easy steps to recover your MS Excel. Click on the link "How to Fix Microsoft Excel 2010 Crashes?".

How to Download and Install Microsoft Office 2019 Products Requested from TechSoup, We will help you to deploy the office setup successfully on your device. 1. Sign in to Microsoft Account 2. Enter Product Key 3. Setup Office

Trend micro protects your multiple online works such as visiting sites, online data transfer online shopping, online banking, uploading data and files online, social media, and many others. |Trend Micro Geek Squad | www.trendmicro/bestbuypc

AVG AntiVirus provides a very interesting capability which allows administrators to remotely install and configure the software from a single location. | | |
install avg with license number |
avg download

Webroot SecureAnywhere Antivirus scans your system quickly and protects you from viruses, rootkits, keyloggers and other harmful programs. | | Install Webroot With Key Code

AVG Secure is designed to keep your digital info safe and secure. Learn about its pricing, security features, and more in this review. | | AVG Download |

Excellent erudition Providing by your Article, thank you for taking the time to share with us such a nice article. Amazing insight you have on this, it's nice to find a website that details so much information about different artists. Kindly visit the LiveWebTutors website we providing the best online assignment help services in Australia.

For More Info: Assignment Help Sydney

What a superb post! I have no words to describe this post because everthing is clear with your wonderfull words. I really feel out of world reading your post, it is full of fresh and usefull. I really appreciate, keep the work continue. ! ! !

I am amazingly charmed with your article. I love the way wherein you form this article. Thankful to you for granting this amazing post to us.
rand mcnally gps update
Trend Micro Login

I read your article it is very interesting and every concept is very clear, thank you so much for sharing.

Business information systems research paper services have become very popular for students studying business & information technology coursework as they engage the best online Information Systems Writing Services.

Yahoo has many users worldwide, and some users might face issues frequently. But sometimes you may face issues like Yahoo mail not responding and it happens because of various factors. But, don’t get panic. Feel free to reach the experts for help.

Medical research paper writing services seekers have been on the rise lately since most learners need Medical Assignment Writing Services, medicine essay writing help and nursing essay writing services.

Amazing and Interesting things to read and learn. Its amazing to find something interesting and cool stuff. Enjoy shayari and motivation shayari and share them.

Very Good Blog . The way of presenting is superb. In new startups business facing lots of problem weather the business is a small shop or a big MNC's Company & Nowadays one of biggest problems is to purchasing IT products that's take lots of money. We Provide IT Products on Rent. We are experts in our Field. Laptop on Rent

My travel life has been easier with Garmin Express. Plus I can get all the latest update through their blogs. I use the Garmin app and is totally upto the mark. I recommend everyone to use Garmin Gps Update and get Garmin life time map update and make your life easier with Garmin Map Update for instant help from Garmin GPS experts.

I did not know the entire benefits of Garmin Nuvi Update. But since I have read this blog on map update, I have installed all available updates for my Garmin device. I must say that this piece of blog has helped me improve navigation experience. I am not suggesting all my friends to read this blog and get Garmin Map Update with this team. For detailed information. Our Garmin GPS professionals will provide instant help.

Studying non-stop for 8-9 hours can drain you out mentally and physically. Take timely breaks to break the monotony. Take 10 minutes after studying for an hour and refresh yourself. It will help you focus and stay energetic to learn better.

Always practice these tips to overcome your fears and perform much better in your exams. You can also check
paper writing help

Great! This has been an incredibly wonderful post. Thank you for providing this info. Check out the way to fix Error Code 0xc00000e9 in Windows 10. Lean how you can fix it at your own or feel free to call our experts on our toll-free numbers or visit our website to know more! is provide you unlimited new movies and new latest tv my blog i will provide you step by step process how to use, Amazon codeus, and

voucher.The MyTV Code is a free application that can be downloaded for free and will let you watch TV on your PC. It's not a TV provider app; it works with any computer that can view web pages.

After using the Amazon Promo code you can Enjoy latest Movies and your Favorite TV shows. Amazon Promo code Provide you Different types Facilities. you can Download you Favorite movie and TV Serial.| ||

Amazon gift card provides you different types amazon/redeem vouchers. After purchasing you can add these gift card in you Amazon account and can check in you “Amazon pay balance” section. if you have sufficient balance then you can do | | |

Get started enjoying Prime Videos on a big screen, follow the steps to get Amazon Prime on My TV, and start watching popular shows with your loved ones and friends. |

I went through your blog, the concepts are very much clear and the information you have shared in your posts is worth appreciable. Keep sharing more.

Sign in with Microsoft 365 login account if you already are using Microsoft’s other services like Outlookcom, Xbox Live, Skype, or OneDrive, it means you can use this account for Microsoft Office 365 login. and find out the best way to download Canon printer drivers. | Ij.start canon | |

Acadecraft offers substantial copyediting services to global business leaders. So, to fine-tune the textual content of professional documents, Acadecraft is always ready. Here, we deliver copy editing solutions in multiple languages spoken worldwide. Hence, to make the documents readable version, connect with the leading copyediting solutions company. Also, take the level of the professional manuscript to the next level.
assessment development solutions
K-12 service provider

All the basic information about every celebrity is available now on the largest database of celebrity heights where you can find all the information and heights of a singer, actor, businessman...

Bertrand Kirby is a professor of Accounting at a leading business school in the US. He has enrolled himself with the digital platform of Study Help Me as part of a mission to alleviate academic stress. He offers customized Assignment Help Malaysia to students and helps them get rid of academic stress. He assures accurate and plagiarism-free work at a very economical cost.

Incredible post I should state and much obliged for the data. Instruction is unquestionably a sticky subject. Be that as it may, is still among the main themes of our opportunity. I value your post and anticipate more. 메이저저사이트

Daftar Situs Agen Slot Online

Daftar Situs Agen Slot Online Fokus utama kami ialah keamanan dan kenyamanan setiap anggota maka dari itu setiap
harinnya Wahana138 berusaha semaksimal mungkin untuk memberikan pelayanan maksimal
sehingga timbul kepercayaan serta kepuasan bagi setiap pemain Wahana138.https://wahana138.xn--mk1bu44c/

To pick the right screen defender, you really want to track down the right one for your sound system model. Regardless of what kind of radio you are utilizing, pick the improved glass screen defender.

Kids R Kids Learning Academy proprietor, Malak Agha, was a darling kindergarten and 1st grade educator in Texas when she started looking for a superior method for offsetting her work with family. Opening Kids R Kids in West Allen, Texas, very nearly quite a while back was only the arrangement she really wanted.

Montessori in Allen tx

Malak's three youngsters, presently 5, 8, and 11 years of age, come to Kids R Kids every day. She gives WatchMeGrow Streaming Video Services to the families in her middle so they can have the very extravagance that she does: better balance between serious and fun activities.
"Educating was so satisfying, however I was passing up those minutes with my own kids," Malak says of her past profession. Like all guardians, that apprehension about passing up exceptional minutes is something Malak knows well.

Daycare in Allen tx

She imparts this story to families that come to her middle. While building our middle, the Kids R Kids corporate office suggested they offer WatchMeGrow.
Whenever forthcoming guardians call her middle, Malak says web based video administration is among the main three elements she brings up. It's a main event. For these guardians, the biometric (finger impression filter) section framework, glass inside walls in study halls and WatchMeGrow web based video from anyplace are the elements that make families pay heed and enlist their youngsters.

Presently, as she plans to open her second Kids R Kids area in Frisco, Texas, she is considerably more persuaded that giving an approach to guardians to associate with their youngsters while they are in her consideration makes her business effective.

Does your child always need to be first? Do they always need to win? I see this behavior a touch bit in a few more youthful kids but greater round youngsters from five years and up. Let’s have a look what we can do in our houses when we see aggressive behavior.

Post a Comment