2

I've set up a very basic ServiceStack project with Bootstrap and I'm trying to get it to see my homepage (Razor View) which it doesn't, so I get the Snapshot of my homepage. Here are the steps I take to create the project:

  1. Create new Project "ServiceStack ASP.Net with Bootstrap"
  2. Open Nuget Server Console to download misssing Servicestack Packages.
  3. Build.
  4. Renamed Services.cs to MyStuffServices.cs and Model.cs to MyStuffModel.cs
  5. Added to 'AppHost.cs':

    SetConfig(new HostConfig
            {
                DefaultRedirectPath = "/Home"
            }); 
    
  6. Moved "_layout.cshtml" from /veiws/shared to /views folder

  7. Added "Home.cshtml" to /views
  8. Added minor text to Home.cshtml
  9. Added to MyStuffService.cs

    public class HomeService : Service
    {
         [DefaultView("Home")]
         public int Get(Home request)
         {
             return 0;
         }
    }   
    
  10. Added to MyStuffModel.cs:

    [Route("/home", "GET")]    
    public class Home : IReturn<int>
    {
    
    }
    
  11. Build.
  12. Run to Internet Explorer - Get Snapshot page.

Here is my AppHost.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Funq;
    using ServiceStack;
    using ServiceStack.Razor;
    using MyStuff.ServiceInterface;

    namespace MyStuff
    {
    public class AppHost : AppHostBase
    {
    /// <summary>
    /// Default constructor.
    /// Base constructor requires a name and assembly to locate web service classes. 
    /// </summary>
    public AppHost()
        : base("MyStuff", typeof(MyStuffServices).Assembly)
    {

    }

    /// <summary>
    /// Application specific configuration
    /// This method should initialize any IoC resources utilized by your web service classes.
    /// </summary>
    /// <param name="container"></param>
    public override void Configure(Container container)
    {
        //Config examples
        //this.Plugins.Add(new PostmanFeature());
        //this.Plugins.Add(new CorsFeature());

        this.Plugins.Add(new RazorFormat());

        SetConfig(new HostConfig
        {
            DefaultRedirectPath = "/Home"
        });
    }
}
}

Here is my Global.asax

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.SessionState;

    namespace MyStuff
    {
        public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
    {
        new AppHost().Init();
    }
}
}

I have no errors and the Package Manager says I'm not missing any packages. I feel like there is a step I'm missing, any help is greatly appreciated.

Update: When executing with debug on, this is what I get when I open with Internet Explorer

@inherits ViewPage
@{
    ViewBag.Title = "Hello World Service";
}
<div>
    <div>
        <input class="form-control input-lg" id="Name" type="text"     placeholder="Type your name">
        <p id="helloResult" style="margin-top: 15px;font-size: large"></p>
    </div>
</div>
<script>
    $('#Name').keyup(function () {
        var name = $('#Name').val();
        if (name) {
            $.getJSON('/hello/' + name)
                 .success(function (response) {
                     $('#helloResult').html(response.Result);
                });
        } else {
             $('#helloResult').html('');
        }
    });
</script>
Jason R.
  • 379
  • 1
  • 6
  • 19
  • This is working for me, you can try looking at your [?debug=requestinfo](https://github.com/ServiceStack/ServiceStack/wiki/Debugging#request-info) to see if there's any StartUp errors. Otherwise can you add your solution to a GitHub repo so we can debug what the issue is? – mythz May 22 '15 at 00:33
  • Using Fiddler, I can tell that my request is getting out with no errors and I get a response (Blue text because I only have HTML in my View) – Jason R. May 22 '15 at 12:41
  • See origional question for Update – Jason R. May 22 '15 at 14:55
  • Could you show how you adding the `cshtml` files and which version of visual studio you are using? Some Visual Studio item templates add references and modify project files based on some assumptions on what the templates are being used with. – Darren Reid May 24 '15 at 01:17
  • I add the .cshtml file by using a empty 'Web Page (Razor v3)" page. It already has the .cshtml extension on it. – Jason R. May 26 '15 at 12:42
  • I want to try your solution but the Public Nuget Server is down – Jason R. May 26 '15 at 12:43

1 Answers1

2

Looks like this problem might be coming from an existing MVC Razor item template that is adding NuGet package Microsoft.AspNet.Razor.3.2.2 which is overriding the ServiceStack.Razor reference.

One way to avoid this is to use the basic HTML item template when adding a new view and name it with the cshtml extension.

HTML file work around

This will avoid unwanted NuGet references coming from the MVC item templates.

To make this more straight forward and obvious, ServiceStackVS extension has been updated to include a simple Razor item template that doesn't add the problematic Microsoft.AspNet.Razor.3.2.2 NuGet packages and simply adds a blank HTML page.

ServiceStackVS Razor item template

If you do accidentally use one of the MVC item templates, to fix your project you will want to do the following steps.

  1. Right click the project -> Manage NuGet Packages
  2. Select Installed packages at the top left tab (VS 2013)
  3. Uninstall Microsoft ASP.NET Razor related packages
  4. UnInstall ServiceStack.Razor
  5. ReInstall ServiceStack.Razor
  6. Delete <runtime> entries for System.Web weren't previously present before adding the Razor item.

Hope that helps.

Darren Reid
  • 2,322
  • 20
  • 25