Unable to display view on TinyWeb system

I am trying to make simple browsing using the TinyWeb framework and the Spark browsing engine.

Enviroment - Visual Studio 2011 and .net 4.5 Developer Preview

Rendering a template without design binding is fine. However, when I bind a model, 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>
+5
source share
2 answers

You are using an anonymous object, which, as far as I know, does not work, you can use a full model class or a dynamic object.

var model = new MyModel { message = "Hello World" };

And then in the view will be <viewdata model="MyModel">or

dynamic model = new { message = "Hello World" };

<viewdata model="dynamic"> .

+5

, ?

.

<viewdata currentProduct="Product"/>

. : http://invalidcast.com/2011/05/tinyweb-series-4-views-model-binding

+4

All Articles