2

我已经用Bootstrap设置了一个非常基本的ServiceStack项目,我试图让它看到我的主页(Razor View),它没有,所以我得到我的主页的快照。下面是我用来创建项目的步骤:ServiceStack不渲染剃刀视图,只看到快照

  1. 新建项目“ServiceStack ASP.Net与引导”
  2. 开放的NuGet服务器控制台下载misssing Servicestack包。
  3. 构建。
  4. 更名Services.cs到MyStuffServices.cs和Model.cs到MyStuffModel.cs
  5. 加进 'AppHost.cs':

    SetConfig(new HostConfig 
         { 
          DefaultRedirectPath = "/Home" 
         }); 
    
  6. 移动 “_layout.cshtml” 从/ veiws /共享到/ views文件夹

  7. 增加了 “Home.cshtml” 到/视图
  8. 添加次要文字Home.cshtml
  9. 添加到MyStuffService.cs

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

    [Route("/home", "GET")]  
    public class Home : IReturn<int> 
    { 
    
    } 
    
  11. 生成。
  12. 运行到Internet Explorer - 获取快照页面。

这里是我的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" 
     }); 
    } 
} 
} 

这里是我的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(); 
    } 
} 
} 

我没有错误,程序包管理器说,我绝不错过任何软件包。我觉得有一个我想念的一步,任何帮助,非常感谢。

更新:当与调试执行,这是我所得到的,当我打开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> 
+0

这对我有用,你可以试着查看你的[?debug = requestinfo](https://github.com/ServiceStack/ServiceStack/wiki/Debugging#request-info)来查看是否有任何启动错误。否则,您可以将您的解决方案添加到GitHub仓库,以便我们调试问题所在? – mythz

+0

使用Fiddler,我可以告诉我的请求没有任何错误,并且我得到了一个响应(蓝色文本,因为我的视图中只有HTML) –

+0

请参阅原始问题以更新 –

回答

2

貌似这个问题可能不同于添加NuGet包Microsoft.AspNet.Razor.3.2.2现有的MVC剃刀项模板现身这是重写ServiceStack.Razor参考。

避免这种情况的一种方法是在添加新视图时使用基本HTML项目模板并将其命名为cshtml扩展名。

HTML file work around

这将避免不必要的NuGet引用从MVC项目模板来。

为了使这个更直接明了,ServiceStackVS extension has been updated包括一个简单的Razor项目模板,不添加有问题的Microsoft.AspNet.Razor.3.2.2 NuGet包,并简单地添加一个空白的HTML页面。

ServiceStackVS Razor item template

如果你不小心使用的MVC项目模板之一,要解决你的项目,你会想要做以下步骤。

  1. 右键单击项目 - >管理的NuGet软件包
  2. 选择Installed packages在左上角的选项卡(VS 2013年)
  3. 卸载Microsoft ASP.NET剃刀相关的软件包
  4. 卸载ServiceStack.Razor
  5. 重新安装ServiceStack.Razor
  6. 删除<runtime> System.Web的条目在添加Razor项目之前并不存在。

希望有所帮助。