Dissecting Razor, part 9: Inline Helpers

In addition to normal and static helpers, Razor supports inline helpers, (also known as templates), which allow you to create lambda expressions that return markup.

An inline helper is created by writing @<tag>Content</tag> as an expression.  This creates a lambda expression that takes a parameter called item and returns a HelperResult object containing the markup.

Inline helpers are used to create functions that take markup as parameters.  For example, you might make an IfLoggedOn helper that displays content if there is a logged-in user, but shows a login link to anonymous users.  To pass the content to the helper, you can use an inline helper:

@helper IfLoggedOn(Func<MembershipUser, HelperResult> content) {
    var currentUser = Membership.GetUser();
    if (currentUser == null) {
        <i>
            To use this content, you must 
            <a href="@Href("~/Login")">log in</a>.
        </i>
    } else {
        @content(currentUser)
    }
}

You can call this method with an inline helper like this:

@IfLoggedOn(
    @<form action="@Href("Add-Comment")" method="post">
        @Html.TextArea("Comment", "Type a comment")
        <input type="submit" name="Submit" value="Add Comment" />
    </form>
)

The @content(currentUser) call in helper method is translated by the Razor compiler into a call to the overload of the Write method that takes a HelperResult (returned from the delegate).  This overload writes the content of the HelperResult to the page without escaping it (Just like a call to a normal helper method).  Functions that take inline helpers can also get the text rendered by the helper by calling ToString() on the HelperResult.

The call to the helper method is compiled to the following C# code:

Write(IfLoggedOn(
item => new System.Web.WebPages.HelperResult(__razor_template_writer => {

    WriteLiteralTo(@__razor_template_writer, "    ");
    WriteLiteralTo(@__razor_template_writer, "<form action=\"");

    WriteTo(@__razor_template_writer, Href("Add-Comment"));

    WriteLiteralTo(@__razor_template_writer, "\" method=\"post\">\r\n        ");

    WriteTo(@__razor_template_writer, Html.TextArea("Comment", "Type a comment"));

    WriteLiteralTo(@__razor_template_writer, "\r\n   ...  </form>\r\n");

})));

The IsLoggedOn method is passed a lambda expression that takes an item parameter and returns a new HelperResult.  The HelperResult is constructed exactly like a normal helper, except that it’s in a lambda expression instead of a normal method.

Like normal helpers, then markup inside inline helpers can contain arbitrary code blocks and code nuggets.  However, inline helpers cannot be nested (since that would create conflicting parameter names)

The item parameter is implicitly typed based on the delegate type that the helper is being passed as (just like normal lambda expressions).  This allows inline helpers to accept a parameter:

@IfLoggedOn(@<text>Welcome, @item.UserName!</text>)

(The special <text> tag is used to pass markup without creating an actual HTML tag)

Next Time: Sections

105 comments:

Thank you!

Thanksa lot for this useful info

summer

Thanks for this content on the blog. Chloe

Some tips on university rankings you can check here. If you do it you will get some idea on which university to attend to

I like the helpful info you provide in your articles. I’ll bookmark your blog and check again here regularly. I am quite certain I’ll learn plenty of new stuff right here! Good luck for the next!

office.com/setup

It is amazing post, i am really impressed of your post. Its really useful. Thank you for sharing this article.
avast login
office.com/setup
Rand McNally Update

Data security is a very big issue nowadays. Viruses harm the data. Here you can know more about how to remove viruses from your computer and makes your data secure and safe.
Easy Steps To Remove Viruses
How to Remove Viruses from your computer?

Are you looking to hire top quality Custom Term Paper Help Services and cheap Legitimate Term Paper Writing Services? Rather than risking abject failure, you should consider hiring Legitimate Term Paper Help Provider.

looking for Epson Printer drivers then epson.com/connect is best place for you. Visit to get latest & updated drivers for all Epson Printer models.

looking for help with Epson Printer issues then call Epson Printer tech Support phone number. Call us to get help & support for for all Epson Printer models.


looking for help with Malwarebytes issues then call Malwarebytes tech Support phone number . Call us to get help & support for for all Malwarebytes related issues.

looking for help with Gmail Password recovery issues then call Gmail Password recovery phone number . Call us to get help & support for for all Gmail Password related issues.

Epson has been known as one of the major brands when it comes to printers. And solve all your printer queries like Epson printer offline issue, Epson printer not printing.

Know why your Epson printer not working and get all solutions for Epson printer offline issue.

Excellent information 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 assignment help services in Australia.

For More Info: Assignment Help Adelaide

Hire UK Essay Writers for competing Law and Other Subject Assignments from studentsassignmenthelp.com. Our writers are proficient in giving law assignment help to the students at a low cost.

Hire our Singapore Translators to complete your academic translation work.Their translation work plagiarism free,an effective,and avails in numerous pair of language.

For best thesis writing help in Auckland and Wellington visit to NZ Assignment Help. Our writers are highly professional and they are giving all the assignment help services for all local as well as international students studied in University of Auckland and University of Wellington. We have a dedicated team of 250+ assignment makers and all of them are giving 100% orignal content for your assignment help.

UAE Assignment Help is the best assignment help service provider in Sharjah and Rakcity. We are writing your content 100% written from scratch. Our highly professional team of 250+ assignment makers are giving 100% unique content for all the assignment help. We are providing our services for all the students studied in United Arab Emirates University and Dubai University.

Greetings, I’m John. I’m a writer living in London, UK. I am a fan of technology, writing. You can visit my store.
Mcafee.com/activate
Mcafee.com/activate

You need to activate your norton products?. you have to visit norton official website for download norton setup then log in your norton account with email and password. follow few steps to activate your norton setup for any help visit website.

norton.com/setup

Dragon NaturallySpeaking remains the benchmark for Windows-based speech-to-text technology.
dragon naturally speaking | dragon naturallyspeaking

McAfee Antivirus protect The basic antivirus program will do all the essential security measure www.mcafee.com/activate always protect your devices McAfee Antivirus applications which are easily available in the market and also on mcafee.com/login .McAfee antivirus offers protection to your important documents and secures your folder and files on these devices. www.mcafee.com login the most well-known antivirus for security and privacy purpose. If you wish to get McAfee antivirus on the operational system, then follow detail by detail guide by and download McAfee mcafee.com my account.
mcafee.com my account antivirus offers protection to your important documents and secures your folder and files on these devices. It's the most well-known antivirus for security and privacy purpose mcafee activate product key

McAfee service offers trusted safety to protect data and devices. So, you can shop, surf & keep all your devices safe online with the convenience of a single subscription.
www mcafee activate | mcafee login my account |
www mcafee com login
mcafee livesafe login | my mcafee account |
mcafee activation code |
mcafee.com my account

there is an expanding interest for accompanies all over the place. Thusly, this

quick increment popular has lead to bargain with quality. Kolkata Escorts

Agencies is really a name that doesn't bargain with the quality with expanding

numbers. So as to make this genuine, we have concocted a brand that gives

genuine Call Girl Services in Kolkata.
if you are intrested than you can contact: Kolkata Escorts

Microsoft Office Suite of products developed by Microsoft that includes Microsoft Word, Excel, Access, PowerPoint, and Outlook. Get some easy steps for easy downloading, installing, activating, and re-installing the Microsoft Office suite by visiting the following links.
Office.com/setup

eset internet security can be installed quickly on each device if the user follows the correct procedure. You can follow the instructions below to install the setup on your devices such as Windows PC, Mac, or mobile device. Best IT security solutions for your home and business devices. Try ESET antivirus and internet security solutions for Windows, Android, Mac or Linux OS.

Enter Norton Setup Product Key and present Norton antivirus on your PC. click Norton.com/setup Enter a New Product Key.Norton.com/setup is the great antivirus software tool that protect your system.Download Norton setup to install Norton antivirus on your computer. Activate your Norton security key for Norton setup.
Norton.com/setup

Greetings, I’m John. I’m a writer living in London, UK. I am a fan of technology, writing. You can visit my store.
Mcafee.com/activate
Norton.com/setup
Mcafee.com/activate
Mcafee.com/activate
webroot.com/safe

I recommend to write such more post like this as it will encourage others.I also recommend visiting mobile app development company

Visit McAfee Activate official site www.mcafee.com/activatein any program.

Enter your 25 digits McAfee Activation Product Key.

Sign in to your McAfee account with accreditations.

Snap Submit and Choose "Nation and language".

Once Logged in, Download your Setup in download organizer.

Run application to introduce, You're good to go to go!
for more information can visit:
mcafee.com/activate

If you suddenly face Mcafee antivirus installation error then you can instantly contact this support service team members of Mcafee and find a solution of complex issues related to Mcafee antivirus.
mcafee.com/activate

Visit McAfee official website www.mcafee.com/activate. Enter your 25 digits Mcafee activation Product Key Enter your Email and password Click Submit and Log in to your account. Once Logged in, Download your Setup in download folder. Run application to install, you’re all set to go!
mcafee.com/activate

Thanks for taking time to share with us such a great article. I found such a significant number of fascinating stuff with regards to your blog particularly its discussion. If you want to keep your Network safe from unwanted threats like viruses, Trojans, and malware, then you can simply download, install and activate the McAfee Product via McAfee.com/Activate | McAfee.com/Activate.

Greetings, I’m John. I’m a writer living in London, UK. I am a fan of technology, writing. You can visit my store.
Mcafee.com/activate
Norton.com/setup
Mcafee.com/activate
Office.com/setup
Office.com/setup

There are academic nursing writing help companies whose ultimate goal is to provide Help with Nursing Writing Services since they are aware most nursing essay writing service part-time students lack enough time to complete their college custom nursing assignments.

McAfee antivirus on their computer, at that point the significant information on their gadget gets shielded from all the infections. McAfee programming obstructs all the hurtful locales which are undependable for the clients' framework
mcafee.com/activate |
mcafee.com/activate

Norton antivirus guarantees excellent virus protection without damaging the device performance while going through the scanning process. Norton antivirus protects the system from infected sites, online browsing, viruses, Trojans, and other harmful software. It also blocks the harmful websites, which can inject code to damage all the data and files on the system. Firstly, purchase the Norton
norton.com/setup
norton setup
norton download
norton account

There are academic nursing writing help companies whose ultimate goal is to provide Help with Nursing Writing Services since they are aware most nursing essay writing service part-time students lack enough time to complete their college custom nursing assignments.

McAfee.Com/Activate – In this 21st century, the greater part the number of inhabitants on the planet utilizes the web to cause installments, to oversee financial balance applications, and numerous online business arrangements and undertakings. As each business and other work is stacking on the web, the cheats are additionally utilizing the web to take information from clients' gadgets. mcafee.com/activate | mcafee.com/activate

McAfee.Com/Activate – In this 21st century, the greater part the number of inhabitants on the planet utilizes the web to cause installments, to oversee financial balance applications, and numerous online business arrangements and undertakings. As each business and other work is stacking on the web, the cheats are additionally utilizing the web to take information from clients' gadgets.
mcafee.com/activate | mcafee activate

Social science coursework writing services are essential and it has become very popular for those seeking social science research paper writing services since most of them seek Social Science Writing Services.

Charlie Wilson is a Microsoft Office expert and has been working in the technology industry since 2002. As a technical expert, Charlie has written technical blogs, manuals, white papers, and reviews for many websites such as office.com/setup. For more information visit on office.com/setup | Norton.com/setup | office.com/setup

Protect our system from antivirus damage , from malware , from anytype of online management. Other wise our some important files can be stolen , so in order to protect visit best computer anitvirus software-
mcafee.com/activate

norton.com/setup
- Norton is one of the best antivirus software which protects your computer from various malware and viruses. It is introduced by Semantic Corp. It works in various Operating Systems like iOS, Windows and even in Android. It provides various security essentials to your system like antispyware, antivirus and antimalware. For any support and help in antivirus please contact us. click on - norton.com/setup

mcafee.com/activate
- McAfee is an antivirus that detects and eliminates harmful viruses from your system. It is one of the best two-way firewall security available for users that blocks infected sites automatically. Also, it offers several premium features that a user can grab to enjoy virtual life conveniently. For More Information Visit- mcafee.com/activate

I am a  web developer, and software engineer currently living in United States. My interests range from entrepreneurship to technology. I am having an experience of more than 6 years in field of Information Technology. i write Blog on technology and we provide service for softwares including antivirus.
richardbranson243
richardbranson243
richardbranson243
richardbranson243
richardbranson243
richardbranson243
richardbranson243
richardbranson243
richardbranson243

Charlie Wilson is a Microsoft Office expert and has been working in the technology industry since 2002. As a technical expert, Charlie has written technical blogs, manuals, white papers, and reviews for many websites such as office.com/setup. For more information visit on office.com/setup | Norton.com/setup | office.com/setup

Dear admin, first of all, thank you so much for sharing such useful information with us, I really like your writing style, you are doing such amazing work and your information is very useful for me, I have also something here to share. norton.com/setup
www.norton.com/setup, Norton product key

You could change someone's life by such an unselfish act Your content is accurate well versed with technology idea.Actually i enjoyed a lot.If you are looking  for  the best antivirus software and support so you should try one of them which may help you a lot. Click below: 
mcafee.com/activate
mcafee.com/activate

McAfee Antivirus additionally squares malware that incorporates noxious sites, rootkits, Trojans, infections, and phishing plans. It gives you in-program reports about the dangers it squares. McAfee Antivirus records the IP tends to associated with the danger, which permits technically knowledgeable clients to maintain a strategic distance from sites associated with those addresses.
mcafee.com/activate | mcafee activate | install mcafee with activation code

mcafee.com/activate as antivirus of virus furnishes you with the security shields to prevent malicious documents from entering in the Desktop, PC/cell phone by means of malware, spyware, rootkit, and Trojan ponies. As individuals all around the globe complete their regular work on their official and PCs, they require absolute protection from a wide range of dangers that these infection records can cause. These infections are produced abruptly from old PC-stuck records or dubious Trojan pony, spyware, and malware online sites.
mcafee.com/activate | www.mcafee.com/activate | mcafee download | mcafee activate

Hey its john,I joned this communities for purpose of promote my technical site.Norton setup is where do you enter the Norton Setup Key at norton.com/setup to enact and introduce Norton item. Norton password generatot tools avoilable on Norton website : Norton setup
norton.com/setup || norton download | norton login | norton.com/setup | Norton setup | norton password generator

office.com/setup : Microsoft Office is utilized by the greater part of the individuals to complete their work in an orderly and sorted out way. office setup comes with various adaptations like Office 2019, Office 2016, Office 2013, and Office 365. Each Microsoft program is utilized for various assignments. Every adaptation of the Microsoft Office Setup needs an item code to complete its actuation procedure. Microsoft Office is utilized for both the reason whether it is for home or business. This assumes a significant job on the off chance that you like to keep your work in an efficient manner : microsoft redeem code

You could change someone's life by such an unselfish act Your content is accurate well versed with technology idea.Actually i enjoyed a lot.If you are looking  for  the best antivirus software and support so you should try one of them which may help you a lot. Click below: 
mcafee.com/activate
mcafee.com/activate

Accounting paper writing services are essential and they have become very popular for those seeking accounting coursework writing services since most of them seek Accounting Writing Services.

There are many Online Coursework writing services and Help with Coursework Writing services to choose from for those stuck with their psychology coursework writing services and nursing coursework writing help services.

Thanks for sharing such a piece of wonderful information. Moreover, it is very true that Entertainment company is ruling the world.
There is everything fame, money but first, you need to set-up your brand availability. Promote your brand, gain customers’ trust, present what the audience wants,
and you will be able to rule the entertainment company.
entertainment company

Greetings, I’m John. I’m a writer living in London, UK. I am a fan of technology, writing. You can visit my store.
Norton.com/setup
Office.com/setup
Office.com/setup
mcafee.com/activate
Norton.com/setup
mcafee.com/activate

Thanks for sharing such a piece of wonderful information. Moreover, it is very true that Entertainment company is ruling the world.
There is everything fame, money but first, you need to set-up your brand availability. Promote your brand, gain customers’ trust, present what the audience wants,
and you will be able to rule the entertainment company.
entertainment company

Thank you for the auspicious writeup. It if truth be told was a enjoyment account it. Glance advanced to more added agreeable from you! However, how can we keep up a correspondence? Digital Marketing Services

here during this article, we are going to be discussing the reason for the twitch error 2000. And also the definition of the twitch error 2000. Twitch Network Error 2000 could be a common error user of Twitch often run into because of the absence of a secure network connection.


Mcafee Login My Account : I have read your article which is quite good to go through with this. Your blog is excellent. You can also visit Mcafee Login My Account https://mcafeepro.com to protect your devices. Mcafeepro antivirus I personally used for 7 years its popular virus protection software which secures my system from the online threats.

This is very informative post, good work, i like this content and wish to read more from you. Thanks for such a informative post. I also like to share
McAfee Login
McAfee Total Protection Login
McAfee Antivirus Login
McAfee Login Mobile

Thanks for sharing this information. Realy very useful.
You can also visit Mcafee account login to protect your devices. Mcafee is an antivirus that provides protection to your device from various online threats. Mcafee account login will help you to use various features.
For more details visit! https://mcafeepro.com/

Mcafee Total Protection Login :Very nice blog and articles. I am really very happy to visit your blog. Now I am finding which I actually want. I check your blog everyday and try to learn something from your blog. Thank you and waiting for your new post. https://mcafeepro.com Visit the website in order to Get Started with the Mcafee Total Protection Login and Activation or you may also contact us anytime at our Toll-free number to get help for McAfee Activate or Install.

Often i read your blog and your blog be very informatic and i realy very appreciate with your blog. At least readers can read about me by clicking following link, i really very thankfull to you.


office.com/setup

office.com/setup

webroot.com/safe | norton.com/setup | norton.com/setup | norton.com/setup

Greetings, I’m John. I’m a writer living in London, UK. I am a fan of technology, writing. You can visit my store.
Office.com/setup
Norton.com/setup
mcafee.com/activate
Office.com/setup
Norton.com/setup

Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing. Nice blog i was really impressed by seeing this blog, it was very interesting and it is very useful for me. Know about Garmin express.


Norton is the best option available in the market. Norton Antivirus is an effective anti-malware scanning engine that is reliable. Because millions of people are browsing the web every day.

norton.com/enroll



When it comes to preventing viruses coming through the Internet, we have the name Norton Antivirus, which we can fully rely on, which protects the Internet and our systems from anti-malware or viruses.

norton.com/enroll



The Roku Device No.1 is a streaming device that is very popular in the United States all over the world. Roku provides users with the best entertainment they have ever wanted. You can turn your computer on very quickly in easy steps.

roku com/link



Roku is a small class tool that lets you view free and paying video content over the Internet on your TV.

www.roku.com/link


Norton is a one of the best antivirus product, that have good capacity to fight with unwanted infection which can harm your computer and networks. Every user should have an antivirus program on their computer and Norton is a good choice.

norton.com/enroll


Roku is an official link that helps user to activate their roku device or TV. In order to activate roku tv or device, user should have roku activation code.

roku.com/link


Roku activation code is an alpha numeric code which helps users to enable their roku device or tv. If the activation phase has been completed, computer would require them to display their fav stuff online at one place.

roku.com/link



If you are a new user with Roku and want to setup your Roku Device, then you can follow the guidelines which is listed with user guide which you received with your purchase. If you are not able to find the user guide then search for step by step Roku device setup or Installation guide.

roku.com/link


Norton products are very effective for Internet threats. However the installation process of the Norton product is still easy for non-technical people or beginners find some obstacles with the install process.

norton.com/setup


Norton is an antivirus that can prevent attacks online, such as malicious ransomware, dangerous updates and hazardous websites. Across today’s environment, millions of people access the internet every day.

norton.com/enroll

Webroot delivers next-generation endpoint security and threat intelligence services to protect businesses and individuals around the globe.
webroot.com/safe ,
www.webroot.com/safe

Reach www.norton.com/setup to get premium Norton services. Enter the Norton setup key at Norton.com/setup, to download, install, and activate Norton setup.

Antivirus is software purpose-built to detect and destroy threats like viruses, malware, ransomware, spyware and others.
canon.com/ijsetup ,
canon ij setup ,
canon ij printer setup ,
hp.com/support ,
www.hp.com/support ,
www.trendmicro.com/bestbuypc ,
www.trendmicro.com besbuypc

office in its latest avatar is the coolest yet the most productive software available in the market. www.office.com/setup ,
office.com/setup , office.com setup ,
office setup

www.office.com/setup 1. Go to office.com/setup for office setup.2.Sign
In to your Microsoft Office Account.3.Find your Office Product Key.4.Enter your Microsoft Office Product Key.5.Download and Install Office.6.Run the Activation wizard.You are all done, Run Office Apps.
https://www.ukofficeoffice.com/
www.office.com/setup

Go to webroot safe website
www.Webroot.com/safe
or
Webroot.com/safe
from your browser. Download, install and activate webroot at www.webroot.com/activate .This may be a best place to introduce yourself and your website or include some credits. http://fbeeswebroot.com/

Very nicely explained and include all important information. I also recommend visiting best astrologer in india

Legit Directory is where you can find verified local businesses, apartments, houses, events and news from all over the United States of America.

I’m Sakht. I’m a writer living in London, UK. I am a fan of technology. You can visit my store.
mcafee.com/activate
Norton.com/setup
mcafee.com/activate
Norton.com/setup

www.webroot.com/safe, Activate Your Webroot Safe setup at Webroot.com/safe as installing Webroot SecureAnywhere in Your PC. Download, install and activate webroot at www.webroot.com/activate.
www.Webroot.com/Safe
www.webroot.com/activate

www.McAfee.com/activate - Download and install McAfee with an McAfee activation key. Learn more about its premium services by visiting mcafee.com/activate.www.macfee.com/activate

Visit McAfee official website www.mcafee.com/activate or mcafee.com/activate.Enter your 25 digits McAfee Product Key.Log in to your McAfee account or Create new.Click Submit and Choose “Country and language”.Once Logged in, Download your Setup.Run downloaded application to install mcafee. Installation Done.www.macfee.com/activate

Visit the official website www.mcafee.com/activate.
Log in or click “Register now” if you are a new user.
Find the product you purchased from McAfee.
Download by clicking the download button.
Pass the license agreement and click the Agreement to proceed.
Follow the instructions on the screen and complete the download process.www. McAfee.com/activate

Plenty Of Fish is a leading social network for dating. It offers the opportunity to meet people of dating age from different countries. This platform not only in a location close to you, but specifically somebody who specializes POF in marriages. Explore fast solutions in
POF Login
Plenty Of Fish Login
Plenty Of Fish Login Page
Pof Login Inbox

123 hp com setup 3830 : Complete 123 HP com setup officejet 3830 setup and this printer is well known to offer high-quality print outs for a low printing cost. Features are many to explore and include the color touch screen, color graphics and much more. Now, to execute 123 hp com setup 3830 , Visit here https://getsupportpro.com/hp/123-hp-com-setup-3830/

You Have Nice Contents Thank you for Sharing this Come to my website to view the contents of my website :
Pof Login In English Login
Pof Login.Com
Plenty Of Fish Login Page
Pof Login Inboxx

I’m Sakht. I’m a writer living in London, UK. I am a fan of technology. You can visit my store.
Norton.com/setup
office.com/setup
mcafee.com/activate

Select the option of Assignment Help when you don’t want to take the stress of writing your assignments or homework. This option allows you to get experts’ assistance for composing your academic papers even in adverse conditions. You can take the online help of academic writers at any time using these kinds of services. If you can’t pay attention to homework writing or don’t have enough time, this option will help you a lot. Handle everything for composing your papers even in adverse conditions via online academic writing services.
Help Assignment
Assignment Help Company

Post a Comment