Click here to Skip to main content
15,034,986 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: PDF to Images for encryption Pin
Member 105489777-Oct-20 7:00
MemberMember 105489777-Oct-20 7:00 
GeneralRe: PDF to Images for encryption Pin
Member 105489776-Oct-20 3:22
MemberMember 105489776-Oct-20 3:22 
QuestionDynamically added controls effecting other controls Pin
Member 149556174-Oct-20 11:22
MemberMember 149556174-Oct-20 11:22 
AnswerRe: Dynamically added controls effecting other controls Pin
Richard Deeming5-Oct-20 2:55
mveRichard Deeming5-Oct-20 2:55 
GeneralRe: Dynamically added controls effecting other controls Pin
Member 149416716-Oct-20 1:16
MemberMember 149416716-Oct-20 1:16 
Questiontrying to get some measurement data to ASP from Microsoft SQL? Pin
auting824-Oct-20 11:07
Memberauting824-Oct-20 11:07 
AnswerRe: trying to get some measurement data to ASP from Microsoft SQL? Pin
Richard Deeming5-Oct-20 2:53
mveRichard Deeming5-Oct-20 2:53 
QuestionComplex View Model with Nested Item List / ModelState Pin
Guillermo Perez18-Sep-20 15:49
MemberGuillermo Perez18-Sep-20 15:49 
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:
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:
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:
<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:
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:
<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!
AnswerRe: Complex View Model with Nested Item List / ModelState Pin
Richard Deeming27-Sep-20 22:21
mveRichard Deeming27-Sep-20 22:21 
QuestionFireFox Upload Images Pin
Member 105489774-Sep-20 6:23
MemberMember 105489774-Sep-20 6:23 
AnswerRe: FireFox Upload Images Pin
Richard Deeming6-Sep-20 23:09
mveRichard Deeming6-Sep-20 23:09 
GeneralRe: FireFox Upload Images Pin
Member 1054897717-Sep-20 5:31
MemberMember 1054897717-Sep-20 5:31 
GeneralRe: FireFox Upload Images Pin
Richard Deeming17-Sep-20 9:06
mveRichard Deeming17-Sep-20 9:06 
GeneralRe: FireFox Upload Images Pin
Member 1054897718-Sep-20 5:48
MemberMember 1054897718-Sep-20 5:48 
GeneralRe: FireFox Upload Images Pin
Richard Deeming20-Sep-20 23:40
mveRichard Deeming20-Sep-20 23:40 
GeneralRe: FireFox Upload Images Pin
Member 1054897717-Sep-20 5:36
MemberMember 1054897717-Sep-20 5:36 
GeneralRe: FireFox Upload Images Pin
Member 1054897718-Sep-20 5:29
MemberMember 1054897718-Sep-20 5:29 
QuestionShow DataTable in Json Pin
Member 149089644-Sep-20 0:20
MemberMember 149089644-Sep-20 0:20 
AnswerRe: Show DataTable in Json Pin
F-ES Sitecore4-Sep-20 2:43
mveF-ES Sitecore4-Sep-20 2:43 
GeneralRe: Show DataTable in Json Pin
Member 1490896421-Sep-20 1:48
MemberMember 1490896421-Sep-20 1:48 
GeneralRe: Show DataTable in Json Pin
F-ES Sitecore21-Sep-20 1:51
mveF-ES Sitecore21-Sep-20 1:51 
GeneralRe: Show DataTable in Json Pin
Member 1490896421-Sep-20 3:47
MemberMember 1490896421-Sep-20 3:47 
GeneralRe: Show DataTable in Json Pin
Richard Deeming21-Sep-20 4:20
mveRichard Deeming21-Sep-20 4:20 
QuestionHotel ERP system Pin
Member 1492170724-Aug-20 4:36
MemberMember 1492170724-Aug-20 4:36 
AnswerRe: Hotel ERP system Pin
Richard Deeming24-Aug-20 4:52
mveRichard Deeming24-Aug-20 4:52 

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.