Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Pass class as list in MVC model

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 110
    Comment on it

    In MVC while working in API for making restful services you need to know your request and response.

    You can pass data or entity from your model as you want.

     

     

    But in any case, you have a requirement of passing multiple records as the request or response then what you need to do is create a list in the model class.

    See the example below:

     public class ProductModel
        {
            public int Id { get; set; }
            public string ProductName { get; set; }
        }

     

     

    After that you can pass that list into your response for getting all the rows that comes from the database in case of response, as in below example:

     public class ProductResponse
        {
            public List<ProductModel> ProductList { get; set; }
            public bool Status { get; set; }
            public string Message { get; set; }
        }

     

     

    Then you can use this model to get all the details by just passing the response in the web API:

     ProductRepository ProdRepo = new ProductRepository();
            public IHttpActionResult GetProduct()
            {
                var product = ProdRepo.GetProduct();
                if (!product.Status)
                {
                    return NotFound();
                }
                return Ok(product);
            }
    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: