Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have this Razor code:
@foreach(var page in Model.Children) { <li> @page.Name </li>}
But how can I pass @page.Name to a C# method to modify it if I have to?
How can I do this:
@foreach(var page in Model.Children) { <li> @ModifyPageName(@page.Name) </li>}
Is this possible?
Yes you can use anything that you normaally use in .net, for example: MyClass.DoSomething(@page.Name).
Yes, I got it to work just now!
For a newbie, do this:
1. Create a Visual Studio class library project.
2. Add your classes in there eg
namespace ActiviaExtensions{ public class BlogMethods { public static string Test(string blogDetails) { return blogDetails.Length.ToString(); } }}
3. ftp the dll to your Umbraco bin directory
4. Call it in your Razor script:
@BlogMethods.Test(@blogpost.postBody.ToString())
And add a using at the top of the Razor file:
@using ActiviaExtensions;
You could also set up Razor Helper methods and drop them into the App_Code folder to make them Globally available to your scripts. See this post for an example
http://joeriks.wordpress.com/2011/03/11/better-structure-for-your-razor-scripts-with-renderpage-in-umbraco/
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Can you call a C# method within Razor (similar to XSLT extension)
I have this Razor code:
@foreach(var page in Model.Children) {
<li>
@page.Name
</li>
}
But how can I pass @page.Name to a C# method to modify it if I have to?
How can I do this:
@foreach(var page in Model.Children) {
<li>
@ModifyPageName(@page.Name)
</li>
}
Is this possible?
Yes you can use anything that you normaally use in .net, for example: MyClass.DoSomething(@page.Name).
Yes, I got it to work just now!
For a newbie, do this:
1. Create a Visual Studio class library project.
2. Add your classes in there eg
namespace ActiviaExtensions
{
public class BlogMethods
{
public static string Test(string blogDetails)
{
return blogDetails.Length.ToString();
}
}
}
3. ftp the dll to your Umbraco bin directory
4. Call it in your Razor script:
@BlogMethods.Test(@blogpost.postBody.ToString())
And add a using at the top of the Razor file:
@using ActiviaExtensions;
You could also set up Razor Helper methods and drop them into the App_Code folder to make them Globally available to your scripts. See this post for an example
http://joeriks.wordpress.com/2011/03/11/better-structure-for-your-razor-scripts-with-renderpage-in-umbraco/
is working on a reply...