Twitter bootstrap ServiceStack未渲染Razor视图,仅查看快照
我已经用Bootstrap建立了一个非常基本的ServiceStack项目,我试图让它看到我的主页(Razor视图),但它没有,所以我得到了我主页的快照。以下是我创建项目所采取的步骤:Twitter bootstrap ServiceStack未渲染Razor视图,仅查看快照,twitter-bootstrap,razor,twitter-bootstrap-3,
servicestack,servicestack-razor,Twitter Bootstrap,Razor,Twitter Bootstrap 3,
servicestack,Servicestack Razor,我已经用Bootstrap建立了一个非常基本的ServiceStack项目,我试图让它看到我的主页(Razor视图),但它没有,所以我得到了我主页的快照。以下是我创建项目所采取的步骤: 创建新项目“ServiceStack ASP.Net with Bootstrap” 打开Nuget服务器控制台下载错误的Servicestack包 建造 将Services.cs重命名为MyStuffServices.cs,将Model.cs重命名为mystuffsmodel.cs 添加到“AppHost.cs
SetConfig(new HostConfig
{
DefaultRedirectPath = "/Home"
});
public class HomeService : Service
{
[DefaultView("Home")]
public int Get(Home request)
{
return 0;
}
}
[Route("/home", "GET")]
public class Home : IReturn<int>
{
}
我没有错误,软件包经理说我没有丢失任何软件包。我觉得我错过了一步,非常感谢您的帮助
更新:在启用调试的情况下执行时,这是我使用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>
@继承ViewPage
@{
ViewBag.Title=“你好,世界服务”;
}
$('#Name').keyup(函数(){
var name=$('#name').val();
如果(姓名){
$.getJSON('/hello/'+name)
.成功(功能(响应){
$('#helloResult').html(response.Result);
});
}否则{
$('#helloResult').html('');
}
});
看起来此问题可能来自现有的MVC Razor项目模板,该模板正在添加NuGet packageMicrosoft.AspNet.Razor.3.2.2
,它将覆盖ServiceStack.Razor
引用
避免这种情况的一种方法是在添加新视图时使用基本HTML项模板,并使用cshtml
扩展名将其命名
这将避免来自MVC项模板的不必要的NuGet引用
为了使这一点更加直接和明显,需要包括一个简单的Razor项目模板,该模板不添加有问题的Microsoft.AspNet.Razor.3.2.2 NuGet包,只添加一个空白HTML页面
如果您不小心使用了一个MVC项目模板,要修复您的项目,您需要执行以下步骤
已安装软件包
项在添加Razor项之前不存在希望这能有所帮助。这对我很有用,你可以试着看看你的电脑,看看是否有任何启动错误。否则,您是否可以将解决方案添加到GitHub repo中,以便我们调试问题所在?使用Fiddler,我可以判断我的请求没有错误,并且得到响应(蓝色文本,因为我的视图中只有HTML)请参见更新的原始问题能否显示如何添加
cshtml
文件以及使用的visual studio版本?某些Visual Studio项模板会根据对模板使用内容的一些假设来添加引用和修改项目文件。我使用空的“网页(Razor v3)”页面添加.cshtml文件。它已具有.cshtml扩展名。
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();
}
}
}
@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>