0

I am using RazorEngine for email templating. I have introduced Take() method into the template. I did this so the authors can dictate how many records they want without us having to change any C# in our code directly. I have tried adding the using statements to the template itself as well as using the fluent configuration and adding the namespaces needed but I am not having any luck.

Error:

'System.Collections.Generic.List<object>' does not contain a definition for 'Take'

Here is my fluent configuration for RazorEngine:

        var config = new FluentTemplateServiceConfiguration(c => 
            c.IncludeNamespaces(
            "System",
            "System.Linq",
            "System.Collections",
            "System.Collections.Generic"));

        using (var service = new TemplateService(config))
        {
            //Razor.SetTemplateService(service);

            dynamic dyModel = model;
            var parsed = string.IsNullOrEmpty(cacheName)
                ? service.Parse(template, dyModel,null, cacheName)
                : service.Parse(template, dyModel,null,null);

            return parsed;
        }

If I purposely state a namespace incorrectly, I do get an error saying it couldn't find it so I know that it is processing the config data but despite that, I am still getting the error.

Any ideas on what I am doing wrong? I am passing in a dynamic model which either is a List or has a List on it.


send json request using php for and api

I am working on some api in which I send information using json.

POST /api/v3/users/ HTTP/1.1

Host: example.com

Content-Type: application/vnd.api+json

Authorization: Bearer ab1dcb45be7e43db2212b0d2b0ca3892

This is the information. Using this will get that response but I don't know how to use this in php and not use js?

get response:

{

    "users": [ {

        "username": "username",

        "phone": "06123",

        "last_name": "myname",

        "address": "some addr",

        "newsletter": true,

        "dob": "1974-12-31",

        "x_id": "123ext",

        "email": "user2@mail.nl",

        "email_verified":  true,

        "social" : {

            "facebook": { "id": "100000730165158"},

            "twitter": {"id": "139029213"},

            "linkedin": {"id": "7EA06I71K5"},

            "google": {"id": "104763295979778440139"}

        }
    }]

}

But I don't know how to use this, meaning how to send request.

4

1 回答 1

0

所以这有点蹩脚,在 RazorEngine 的 wiki 上有一张票说这是​​固定的,所以要么我使用错了,要么没有修复,但这是我必须做的才能让它在 razor 文件中工作。

var topFive = ((List<dynamic>) Model.MyList).Take(5);
于 2013-11-27T15:41:20.777 回答