Does the Razor View Engine in ASP.NET support structs or custom classes?
It appears that the Razor view engine supports Dictionary<>
, List<>
, and other collections. Does Razor support structs or cus开发者_StackOverflow社区tom classes such as below? If so what is the approach to use them?
struct gc {
public string code;
public string definition;
};
public class gc2 {
public string code;
public string definition;
};
The statements above are throwing compilation errors. (i.e. Compiler Error Message: CS1513: } expected
)
I tried a work around.
By declaring an empty JSON object string - you can decode the string in Razor. By default, this creates the object which can then be used.
It looks kind of like this:
var word = "{\"code\" : [],\"font\" : []}";
var p = Json.Decode(word);
Now, p somewhat has the structure of the object needed.
However - if you try to fill the object - it becomes outside the bounds of the array.
精彩评论