我已经用Bootstrap设置了一个非常基本的ServiceStack项目,我试图让它看到我的主页(Razor View),它没有,所以我得到我的主页的快照。下面是我用来创建项目的步骤:ServiceStack不渲染剃刀视图,只看到快照
- 新建项目“ServiceStack ASP.Net与引导”
- 开放的NuGet服务器控制台下载misssing Servicestack包。
- 构建。
- 更名Services.cs到MyStuffServices.cs和Model.cs到MyStuffModel.cs
加进 'AppHost.cs':
SetConfig(new HostConfig { DefaultRedirectPath = "/Home" });
移动 “_layout.cshtml” 从/ veiws /共享到/ views文件夹
- 增加了 “Home.cshtml” 到/视图
- 添加次要文字Home.cshtml
添加到MyStuffService.cs
public class HomeService : Service { [DefaultView("Home")] public int Get(Home request) { return 0; } }
加入MyStuffModel.cs:
[Route("/home", "GET")] public class Home : IReturn<int> { }
- 生成。
- 运行到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>
这对我有用,你可以试着查看你的[?debug = requestinfo](https://github.com/ServiceStack/ServiceStack/wiki/Debugging#request-info)来查看是否有任何启动错误。否则,您可以将您的解决方案添加到GitHub仓库,以便我们调试问题所在? – mythz
使用Fiddler,我可以告诉我的请求没有任何错误,并且我得到了一个响应(蓝色文本,因为我的视图中只有HTML) –
请参阅原始问题以更新 –