Search code examples
f#websharperfunscript

WebSharper issue on getting started


So I have been looking at developing RIA or MVC applications using F# and I saw that there were two options :

  1. FunScript
  2. WebSharper

I have a Visual Studio 2012 version and it's a student edition. So I just followed the getting started link here

Now after following the instructions, I am not able to get the test page. So I would need some directions/help to proceed. So this is what happens :

  1. After creating a Web Application Sitelets using the New Project, I get an error in the Site.fs page. It gives the same "module or namespace not defined". So what I try to do is use Manage NuGet References to load the references for WebSharper and it removes the error. Now I have already installed WebSharper in my machine. Shouldn't there be an easy way to link the WebSharper libraries. If so how can I do it? What is it that I am doing wrong here.

  2. After resolving the issue I follow the getting started code to the last line in that page, I get an error in this code sample :

let HomePage = Template "HomePage" <| fun ctx -> [ Div [Text "HOME"] Links ctx Div [new Controls.HelloControl()] ]

Essentially the page does not like the new Div [ new Controls.HelloControl()] added and so it throws an error.

I am a beginner to Microsoft technologies and even the Visual Studio IDE. I am used to Eclipse and figuring out how it works has never been a problem. But I am completely clueless here on how to make this work.

At the end of it I also have a query on where I can find updated documentation on a decent introduction to both FunScript and WebSharper.


Solution

  • For the original issue, the problem is with the sample on the website -- somehow the whitespace has been munched, the code should be:

    let HomePage =
        Template "HomePage" <| fun ctx ->
            [
                Div [Text "HOME"]
                Links ctx
                Div [new Controls.HelloControl()]
            ]
    

    Now for "A Project with an Output Type of Class Library cannot be started directly":

    The solution consists of two projects: a C# Web project, which hosts the web application, and an F# library project, which contains the actual code. All you have to do is right-click on the C# project in the solution explorer and select "Set as Startup Project". This way, when you press "F5", instead of trying to run the F# library project, it will start the web project.