As we know we can supply values for parameters on Macros. When we insert a macro onto a template, we are prompted to supply the values for the parameters. Here I would like to show you that we can also do this in a Razor script as well.
Let’s say we have a Razor script file called “WelcomeMessage.cshtml” created under the Scripting files and we have a corresponding macro called “Welcome Message Macro”. The duty of our Razor script here is to display a Welcome message. Well, we have set a macro parameter called “AttendeeName” which accepts a name when inserted on a template. Now we need to modify our welcome message to display as “Welcome [AttendeeName], have a nice time here!!!”. Here in the given message [AttendeeName] should be replaced by the value assigned as a macro parameter.
This can be easily implemented in Razor script. In order to implement this, we need to make use of the following syntax in Razor scripts as follows
@Parameter.AliasName (please note this is not case sensitive)
So in our scenario, the whole Razor script would be as given below
Welcome @Parameter.AttendeeName, have a nice time here !!!
So guys have fun with Razor :-)
About .NET , C#, ASP.NET , SharePoint , Umbraco , SQL Server , Business Intelligence and more...
Subscribe to:
Post Comments (Atom)
Installing ASP.NET MVC
Installing ASP.NET MVC Before we dive deep into the ASP.NET MVC, let’s install it our development machine. This is very straight forwa...
-
Here lets discuss about the various Parameter modifiers that can be used to manage how arguments are passed to methods. Default by Value...
-
When you begin developing Windows Phone applications, you need to choose a framework one from Silverlight or XNA framework. Let’s list down ...
-
Visual Studio Test Professional 2010 is an integrated testing toolset from Microsoft which provides a complete plan-test-track workflow for ...
No comments:
Post a Comment