Click here to Skip to main content
15,885,278 members
Home / Discussions / C#
   

C#

 
AnswerRe: Better way to handle 50 labels Pin
Richard Andrew x6421-Sep-20 16:12
professionalRichard Andrew x6421-Sep-20 16:12 
AnswerRe: Better way to handle 50 labels Pin
OriginalGriff21-Sep-20 20:58
mveOriginalGriff21-Sep-20 20:58 
AnswerRe: Better way to handle 50 labels Pin
Gerry Schmitz22-Sep-20 6:45
mveGerry Schmitz22-Sep-20 6:45 
AnswerRe: Better way to handle 50 labels Pin
BillWoodruff22-Sep-20 7:59
professionalBillWoodruff22-Sep-20 7:59 
AnswerRe: Better way to handle 50 labels Pin
Mycroft Holmes22-Sep-20 12:20
professionalMycroft Holmes22-Sep-20 12:20 
GeneralRe: Better way to handle 50 labels Pin
Member 149437371-Oct-20 18:52
Member 149437371-Oct-20 18:52 
AnswerRe: Better way to handle 50 labels Pin
Member 1494373728-Sep-20 13:41
Member 1494373728-Sep-20 13:41 
QuestionComplex View Model with Nested class Properties / Array Submit Pin
Guillermo Perez18-Sep-20 15:50
Guillermo Perez18-Sep-20 15:50 
I'm sorry to bother you, I just have a question regarding how to validate a list of object when is inside other list... I do have a list of cities, each city has another list of zones, an example could be like this:
C#
public class City
{
        public int Id { get; set; }        
        public string CityName { get; set; }
        public virtual List<Zone> Zones { get; set; } = new List<Zone>();
}

public class Zone
 {
        public int Id { get; set; }
        public string ZoneName { get; set; }

        public int CityId { get; set; }
        public virtual City City { get; set; }
}

Now, as you can see, the City is the principal and the Zone is the dependent class. Now I decided to pass what I have into my database to a view with a form to make changes to these Cities and their Zones, so I created a view model like this:
C#
public class SettingsModel
    {
        public City NewCity { get; set; }
        public List<City> CurrentCities { get; set; }
    }

The first property is to create a new City that is not in the db. The other list contains the Cities already in the database. So I started by creating a list of forms using a for loop (not foreach) that uses an index. At the end, it produces something like this:
HTML
<form method="post" action="/Administration/UpdateCity">
...
<input type="hidden" id="CurrentCities_0__Id" name="CurrentCities[0].Id" value="7">
<input type="text"  id="CurrentCities_0__CityName" name="CurrentCities[0].CityName" value="Austin">
...
</form>
...
<form method="post" action="/Administration/UpdateCity">
...
<input type="hidden" id="CurrentCities_1__Id" name="CurrentCities[1].Id" value="4">
<input type="text"  id="CurrentCities_1__CityName" name="CurrentCities[1].CityName" value="Dallas">
...
</form>

as far as I understand, in the receiving action method (POST), I should use the [Bind(Prefix="CurrentCities")] to remove the unnecessary class name of the field name and, should specify a list<city> (or IEnumerable or Array) to tell that the object received is an array. in other words:
C#
public IActionResult UpdateCity([Bind(Prefix = "CurrentCities")]List<City> myCity) 
{
...
}

My question is: When I try to add a form in the same way for the Zones property of City, I end with the form fields named as:
HTML
<input type="text" id="CurrentCities_0__Zones_0__ZoneName" name="CurrentCities[0].Zones[0].ZoneName" value="Austin Metro Area">
...
<input type="text" id="CurrentCities_1__Zones_0__ZoneName" name="CurrentCities[1].Zones[0].ZoneName" value="San Antonio Metro Area">

As you can see, now all the fields have an extra index indicator like this "CurrentCities[0].Zones[0]" and I was wondering, how can I get this object in the POST action method? how can I specify a Bind Prefix of this kind? and how could I specify that the item is a collection item of other collection item?? Please help and thank you for your patience!
GeneralRe: Complex View Model with Nested class Properties / Array Submit Pin
Richard MacCutchan18-Sep-20 21:47
mveRichard MacCutchan18-Sep-20 21:47 
AnswerRe: Complex View Model with Nested class Properties / Array Submit Pin
Gerry Schmitz19-Sep-20 2:43
mveGerry Schmitz19-Sep-20 2:43 
QuestionInsert on database contents of word file using OpenXML and c# Pin
cms965118-Sep-20 8:40
cms965118-Sep-20 8:40 
AnswerRe: Insert on database contents of word file using OpenXML and c# Pin
Gerry Schmitz18-Sep-20 9:36
mveGerry Schmitz18-Sep-20 9:36 
GeneralRe: Insert on database contents of word file using OpenXML and c# Pin
cms965118-Sep-20 9:52
cms965118-Sep-20 9:52 
GeneralRe: Insert on database contents of word file using OpenXML and c# Pin
Gerry Schmitz18-Sep-20 11:18
mveGerry Schmitz18-Sep-20 11:18 
GeneralRe: Insert on database contents of word file using OpenXML and c# Pin
cms965118-Sep-20 20:13
cms965118-Sep-20 20:13 
GeneralRe: Insert on database contents of word file using OpenXML and c# Pin
Dave Kreskowiak18-Sep-20 18:45
mveDave Kreskowiak18-Sep-20 18:45 
GeneralRe: Insert on database contents of word file using OpenXML and c# Pin
cms965118-Sep-20 20:11
cms965118-Sep-20 20:11 
GeneralRe: Insert on database contents of word file using OpenXML and c# Pin
Pete O'Hanlon18-Sep-20 23:10
mvePete O'Hanlon18-Sep-20 23:10 
GeneralRe: Insert on database contents of word file using OpenXML and c# Pin
Gerry Schmitz19-Sep-20 2:17
mveGerry Schmitz19-Sep-20 2:17 
QuestionThe forms are cut for me using high resolution on WinForm Pin
goldsoft18-Sep-20 1:51
goldsoft18-Sep-20 1:51 
AnswerRe: The forms are cut for me using high resolution on WinForm Pin
Gerry Schmitz18-Sep-20 7:39
mveGerry Schmitz18-Sep-20 7:39 
GeneralRe: The forms are cut for me using high resolution on WinForm Pin
goldsoft18-Sep-20 9:57
goldsoft18-Sep-20 9:57 
GeneralRe: The forms are cut for me using high resolution on WinForm Pin
Gerry Schmitz18-Sep-20 11:21
mveGerry Schmitz18-Sep-20 11:21 
RantRe: The forms are cut for me using high resolution on WinForm Pin
DerekT-P18-Sep-20 10:48
professionalDerekT-P18-Sep-20 10:48 
AnswerRe: The forms are cut for me using high resolution on WinForm Pin
BillWoodruff19-Sep-20 9:11
professionalBillWoodruff19-Sep-20 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.