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>
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.
var model = new MyModel { message = "Hello World" };
And then have <viewdata model="MyModel">
in the view or,
dynamic model = new { message = "Hello World" };
And then specify <viewdata model="dynamic">
in the view.
Do you not have to let spark now what model is?
e.g.
<viewdata currentProduct="Product"/>
see here: http://invalidcast.com/2011/05/tinyweb-series-4-views-model-binding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With