|
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!
|
|
|
|
|
You posted this also in the ASP.NET forum. Please do not crosspost.
|
|
|
|
|
There, you nailed it. In web interfaces, there is no (well-known) pattern that will allow you to (reasonably) add or update more than one record at a time.
It's:
- Add a city
- Add a zone
- Add another zone
- Add another city
- Add a zone
- Edit a city
- Edit a zone.
The classic Edit and Delete action per row. 1st gen client-server.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hello, I need your help.
I want to read a .docx file line by line and insert chapters and paragraphs of the chapter in database table.
I have tried using Microsoft.Office.Interop.Word to read the document, without success because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
Now I read on google that the suitable tool for this is OpenXML.
My file.docx is divided for chapters and paragraphs of the chapter
The structure of file.docx
Chapter 1 - Events
-alert or disservices
-significant activities
Chapter 2 – Safety
-near miss
-security checks
Chapter 3 – Training
-environment
-upkeep
I need insert on database table according with this schema
https://i.stack.imgur.com/41YQL.png[^]
How to do resolve this?
Thanks in advance for any help or suggestion
Chevy
DROP TABLE IF EXISTS `chapters`;
CREATE TABLE `chapters` (
`chapter` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
`subheading` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
`contents` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
`sID` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`sID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
|
I don't know about "OpenXML", but if you save your docx in MS Word as a "Word XML document", you can actually "see" the xml and make sense of your document if you then open it in Xml Notepad, for example.
("OpenXml" seems to have it's own internal "non-xml" format. Bizarre).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Thanks for suggestion, do you have any example for me?
The Google search is empty...
|
|
|
|
|
Which part?
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Don't have found anything for my case in OpenXML tutorials with Google search
|
|
|
|
|
The DOCX format is really just a .ZIP file with a bunch of XML files in it.
You can just rename the .docx file to .zip and open it in any .zip tool.
|
|
|
|
|
I'm sorry, I don't understand your suggestion...
|
|
|
|
|
Unzip the docx file and take a look at the xml files inside.
|
|
|
|
|
Thanks ... They should have called it .docxzip then.
Or .odoc.
Or anything except .docx.
I know what a .jar file is ... I guess they could have called it .javax, but didn't.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I got a new laptop with very high resolution. I increased the size text, apps and other to 150%
i work on WinForm program using Visual-Studio 2019.
All the forms in my program are cut and everything goes wrong on the screen.
i try this:
app.manifest
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedos id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}">
app.config
<system.windows.forms.applicationconfigurationsection>
<add key="DpiAwareness" value="PerMonitorV2">
<add key="EnableWindowsFormsHighDpiAutoResizing" value="false">
i work on .NET Framework 4.7.2
i also try this:
https://docs.microsoft.com/en-us/dotnet/desktop/winforms/high-dpi-support-in-windows-forms?view=netframeworkdesktop-4.8
and also this on the main of every form: (Each time something different)
this.AutoScaleMode = AutoScaleMode.Font;
this.AutoScaleMode = AutoScaleMode.Dpi;
this.AutoScaleMode = AutoScaleMode.None;
I have already tried everything .... and nothing helps. any idea ?
thanks
|
|
|
|
|
If the size of the "controls" (on the forms) was fixed, "auto sizing" only the form makes no difference; everything has to be able to resize itself based on its container.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Thanks for the answer, so if I understood correctly, I need all the controls to be AutoSize = true ?
|
|
|
|
|
You prototype to see what works and what doesn't ... for "your" app. I'm not going to tell you to change "everything" to autosize. Sometimes you want something fixed size so you don't get a lot of empty space.
IMO, the "secret" to Windows Forms "fluid" design is to make "everything" "dockable"; that's the basis for fluid design in XAML (wpf and uwp).
Most Windows Forms (designers) use absolute positioning by default.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
modified 18-Sep-20 17:47pm.
|
|
|
|
|
Yep, Win10 is a pile of crap. If I size everything to 100%, it's so miniscule that it's totally unreadable (for me, in my more mature years). So I set magnification to 125%; most text is now readable, but some older apps remain unaffected. In MS Office most texts are fine, but the icons are absolutely tiny; fortunately I can generally remember the sequence, but otherwise I couldn't use Office apps. Most pop-up boxes from Windows are OK, but some - core Windows pop-ups - are the right size but their controls are misplaced, sometimes outside the boundary of the form. When this happens with an OK or CANCEL button the popup becomes unusable and I have to change the default Windows setting temporarily. Then there's a whole raft of applications - both Microsoft and 3rd party - where the text is displayed fuzzy and makes my eyes hurt to read it.
All this, and it seems that 125% is the default for Win10 on my screen size / resolution. Windows 3.1 was better than this!
|
|
|
|
|
I had similar problems until I set AutoScaleMode to Font. However, I have my 4k laptop screen set to 1920x1080 as well as 150% scaling ... I have vision problems.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
I also have a laptop with 4K screen (3840X2160) 220% scaling and I also changed AutoScaleMode to Font. and still cut the screens in the my program
|
|
|
|
|
I think you can focus this discussion more by adding to your original post specific details: for example, you create a new WinForm project, size the main form to 800x600, set the StartPosition to 'CenterScreen.
Drop Labels in each corner of the Form: then, run the project, and describe what you observe.
You might also put this code in the main form Load event:
Rectangle r1 = Screen.PrimaryScreen.Bounds;
Rectangle r2 = this.Bounds;
Rectangle r3 = this.ClientRectangle;
Rectangle r4 = this.DisplayRectangle;
Console.WriteLine($"screen {r1}\nform bounds {r2}\nform displayrect {r3}\nform clientrect {r2}"); And, try varying the AutoScaleMode ... the goal being to identify the visually unexpected more clearly.
Hope it helps !
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Well according to the .net Referencesource its:
public const double NaN = (double)0.0 / (double)0.0;
But how? and Why? and foremost how?
0 / 0 should be compiler like " "
what is this compiler trickery?
|
|
|
|
|
|
Can you explain to me why this does not compile.
public class IBase<T> where T:IBase<T>{
public void Foo(T arg){
}
void Bar(){
Foo(this);
}
}
public class Deriv:IBase<Deriv>{
void Bar2(){
this.Foo(this);
}
}
|
|
|
|
|
It'#s complicated: and MS has described it better than I could: Generic Classes - C# Programming Guide | Microsoft Docs[^] - it has a section on inheriting from generic classes.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In IBase<T> , all instance of T are guaranteed to be derived from IBase<T> . But an instance of the current class is not guaranteed to be assignable to T .
Imagine a contrived example:
public class B<T> where T : B<T>
{
public void Foo(T) { }
public void Bar() => Foo(this);
}
public class C : B<C>
{
public void Bar2() => Foo(this);
}
public class D : B<C>
{
public void Bar3() => Foo(this);
public void Bar4() => Bar();
} If the method were allowed in the base class, then class D could simply call that method, and you would pass an instance of class D to a parameter which required an instance of class C . Since there is no conversion from D to C , this would break the runtime.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|