Can not render view in TinyWeb framework
Asked Answered
B

2

5

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>
Broaddus answered 12/11, 2011 at 14:58 Comment(0)
D
5

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.

Dextrose answered 12/11, 2011 at 15:24 Comment(1)
Setting a full model class worked. Could not get the dynamic model to work.Broaddus
S
4

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

Suppressive answered 12/11, 2011 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.