Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not render view in TinyWeb framework

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>
like image 574
Cogslave Avatar asked Nov 12 '11 14:11

Cogslave


2 Answers

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.

like image 198
Tom Bell Avatar answered Nov 07 '22 02:11

Tom Bell


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

like image 4
Johnno Nolan Avatar answered Nov 07 '22 01:11

Johnno Nolan