9

Nancy で、POST リクエストのコンテンツを動的タイプにバインドする方法はありますか?

例えば:。

// sample POST data: { "Name": "TestName", "Value": "TestValue" }

// model class
public class MyClass {
    public string Name { get; set; }
    public string Value { get; set; }
}

// NancyFx POST url
Post["/apiurl"] = p => {

    // this binding works just fine
    var stronglyTypedModel = this.Bind<MyClass>();

    // the following bindings do not work
    // there are no 'Name' or 'Value' properties on the resulting object
    dynamic dynamicModel1 = this.Bind();
    var dynamicModel2 = this.Bind<dynamic>();
    ExpandoObject dynamicModel3 = this.Bind();
    var dynamicModel4 = this.Bind<ExpandoObject>();

}
4

4 に答える 4

-1

よくわかりませんが、試すことができます:

dynamic model = new ExpandoObject();
model = Request; //or Request.Form
return View["ViewName", model];

動作するかどうか教えてください:)

于 2013-05-23T23:22:33.410 に答える