Playing with Razor in Umbraco : an old skool contact form

This is clearly not the way a state of the art contact form should be made in Umbraco. But to learn and have fun with the new Razor possibilities I created a very basic contact form:

Edit : please also see this newer article about how to make a simple contact form with better code structure.

Here’s the complete code

@if (!IsPost)
    <form method="POST">
    Tell us what you think:<br/><textarea name="msg" rows="3" cols="40"></textarea><br/>
    Your name:<br/><input type="text" name="name"/><br/>
    <input type="submit" value="Send your message to us"/>
    var message = Request["msg"];
    var name = Request["name"];
    umbraco.library.SendMail("","","Message from " + name,message,false);
    <strong>Thank you for your message @name:</strong><br/>@message

6 thoughts on “Playing with Razor in Umbraco : an old skool contact form

  1. Adding functions was possible long time ago using script runat server like this (I use it a lot):

    <script runat=”server”>
    public int GetLevel() {
    string path = umbraco.presentation.nodeFactory.Node.GetCurrent().Path;
    int count = 0;
    foreach (char c in path)
    if (c == ‘,’) count++;
    return count;

  2. of course like your web-site however you have to test
    the spelling on quite a few of your posts. A number of them are rife with spelling issues and I in finding
    it very bothersome to tell the truth nevertheless I’ll definitely come back again.

  3. I tweaked it a bit, but this is excellent. Did not know it was possible to simply have a MacroPartial with it’s own little form and post to itself. Brilliant, and so much easier than that MVC stuff, with controllers and models and surfaces and who knows what else spread everywhere.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s