Home How to add a value to a class if the class contains LIST<class>

# How to add a value to a class if the class contains LIST<class>

Kirill Zorin
1#
Kirill Zorin Published in 2018-02-11 09:51:34Z
 I have a class graf. public class Graf { public List first { get; set; } public List second { get; set; } }  This class contains List public class Point { public int x { get; set; } public int y { get; set; } public Point(int x, int y) { this.x = x; this.y = y; } }  I need to add a Point into class Graf from index.cshtml: @model WebApplication2.Models.Graf
--------??
 But i dont now how i can input into Graf class Point? How can I do it?
Artur Lavrov
2#
Artur Lavrov Reply to 2018-02-11 15:51:34Z
 Ok. So let's start from a client-side code.I suppose that you have a next Index.cshtml view. 
--------??
 Than you need a code that post new Point object from your view to controller.It could be like something like this: 
X value:
Y value:
 In your controller you should create action with following signature [HttpPost] public async Task InsertPoint(Point point) { //Validation and insertion to list return View(); }  NB It's not an ideal solution. You could perform this task in many different ways. My aim, is just to show you the basic idea how it could be done. If you need more information you could start from this article And of course, keep in mind that google is your good friend.
 You need to login account before you can post.
Processed in 0.317316 second(s) , Gzip On .