Creating Methods with Parameter in Razor Syntax

In this chapter you will learn
  • How to create methods with parameter in razor syntax?
  • Programming Example

How to create methods with parameter in razor syntax?

You can simply create methods in razor syntax using @functions keyword. See the following example for better demonstration.

Programming Example

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        @functions{
            public int sum(int x, int y)
            {
                return x+y;
            }
        }
        <h3>Add of 5 + 6 is @sum(5,6)</h3>
        <h3>Add of 9 + 10 is @sum(9,10)</h3>
    </body>
</html>
  Output
Add of 5 + 6 is 11 Add of 9 + 10 is 19

Summary

In this chapter you learned to declare or define methods with parameter in razor syntax. In the next chapter you will learn to handle exceptions and errors in razor syntax.

More Articles

 

Share your thought



PLEASE DISABLE ADBLOCKER AND SUPPORT US!

Please support us by enabling ads on this page. Refresh

YOU DON'T LIKE ADS, WE ALSO DON'T LIKE ADS!
 
But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.