开发者

Spark View Engine and using viewdata confusion

I can't seem to get a grasp on how to use the viewdata structure in the spark view engine. I have the following code in my controller:

        // Retrieve the project list from the database
        var projects = from p in _context.Repository<project>()
                       orderby p.name ascending
                       select p;

        return View(projects.ToList<project>());

This code works, as I have unit tests returning the correct projects, and my non-spark view worked perfectly. Now I am trying to switch to Spark View Engine and I'm just confused on the syntax. As a side note, I have verified that spark view engine is working and reading my .spark view.

Here is what I am using in my list.spark view:

<h2>Available Projects</h2>
<viewdata model="IList[[project]]"/>
Cou开发者_Go百科nt: ${model.count}

When rendering this view the following error occurs:

.../List.Spark(3,16): error CS0103: The name 'model' does not exist in the current context 

This is referring to the model.count line. Why doesn't this work? I tried passing the project list to the ViewData["projects"] (and replaced model in the spark code with projects) and I get the same error (take out the model.count for projects.count).

This is probably something stupid, but I can't seem to figure this out.

Update:

Well I fixed this. It seems that the MVC2 web.config file created by VS 2010 Beta 2 was bad. I used a MVC2 web.config file created by VS 2010 RC and it now works. Thanks!


I think you want this:

<h2>Available Projects</h2>

<viewdata model="IList[[project]]"/>
Count: ${ViewData.Model.Count}

or this:

<h2>Available Projects</h2>

<viewdata model="IList[[project]]"/>
<var model="ViewData.Model" />
Count: ${model.Count}

The viewdata element declares the types of the entries in the ViewDataDictionary. For "model", this is actually declaring the type of the ViewDataDictionary's Model property.

Note also that these expressions and type names are C# code, and thus case sensitive.

EDIT: syntax updated for 1.0 stable release.

Reference - using view data in the documentation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜