简体   繁体   English

mvc4模型定义以及如何将其作为List返回?

[英]mvc4 model defines and how to return it as List?

public class resultInfo
    {
        public String result { get; set; }
        public String errorCode { get; set; }
        public String exceptionMsg { get; set; }
        public String message { get; set; }
        public String jobType { get; set; }
        public String menuId { get; set; }        
    }

This is a model for controller's process result. 这是控制器处理结果的模型。 I'm gonna use this throughout the whole controllers. 我将在整个控制器中使用它。

Sometimes I could just set only 'result' value or sometimes set two or more values on the items. 有时我只能设置“结果”值,或者有时在项目上设置两个或多个值。

and I want it to be a list, so that I can give the result information to the client in JSON object. 我希望它是一个列表,以便可以将结果信息以JSON对象的形式提供给客户端。

I know how to convert List object to Json, but don't know how to make the model List object. 我知道如何将List对象转换为Json,但不知道如何制作模型List对象。

It works like any other model.. 它像任何其他模型一样工作。

At the top of your view just declare it as @model List<resultInfo> and pass your list from the controller 在视图顶部只需将其声明为@model List<resultInfo>并从控制器传递您的列表

Then in your view you have the @Model property with a reference to your list model. 然后,在您的视图中,您将拥有@Model属性,并带有对列表模型的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM