无法在 TinyWeb 框架中渲染视图
我正在尝试使用 TinyWeb 框架和 Spark 视图引擎渲染一个简单的视图。
环境是 Visual Studio 2011 开发者预览版和.net 4.5
渲染没有模型绑定的模板效果很好。 但是,当我绑定模型时,它不再起作用。
我收到此错误: 当前上下文中不存在名称“模型”。
处理程序:
public class IndexHandler
{
Route route = new Route("/");
public IResult Get()
{
var model = new { message = "Hello World" };
return View.Spark(model, "Views/base.spark");
}
}
查看:
<html>
<head>
<title>This is a test</title>
</head>
<body>
<p>${Model.message}</p>
</body>
</html>
I am trying to render a simple view with the TinyWeb framework and Spark view engine.
Enviroment is Visual Studio 2011 developer preview & .net 4.5
Rendering a template with no model binding works fine.
However when I bind a model then it no longer works.
I get this error:
The name 'Model' does not exist in the current context.
Handler:
public class IndexHandler
{
Route route = new Route("/");
public IResult Get()
{
var model = new { message = "Hello World" };
return View.Spark(model, "Views/base.spark");
}
}
View:
<html>
<head>
<title>This is a test</title>
</head>
<body>
<p>${Model.message}</p>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在使用一个匿名对象,据我所知,该对象不起作用,您可以使用完整的模型类或动态对象。
然后在视图中添加
,或者,然后在视图中指定
。You're using an anonymous object which as far as I am aware will not work, you can either use a full model class or a dynamic object.
And then have
<viewdata model="MyModel">
in the view or,And then specify
<viewdata model="dynamic">
in the view.你现在不用让spark 是什么型号吗?
例如,
请参见此处: http://invalidcast.com/2011/05 /tinyweb-series-4-views-model-binding
Do you not have to let spark now what model is?
e.g.
see here: http://invalidcast.com/2011/05/tinyweb-series-4-views-model-binding