Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
5
votes1
answer285
viewsA: What is "Helper" for in Asp.Net MVC?
Please explain to serve Helper on Asp.Net MVC. Helper is a static class, outside the group of Controllers, which has replicable logic for the rest of the system. By "replicable logic", it is any and…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
2
votes1
answer295
viewsA: How to return several values of a class?
The correct way is to define a Viewmodel: public class UsuariosViewModel { public AspNetUser Model1 { get; set; } public AspNetUser1 Model2 { get; set; } } I mean, you can make a Helper thus (Model…
-
9
votes3
answers3624
viewsA: When to use asynchronous or synchronous method?
When to use asynchronous or synchronous methods in controllers (Index, search, delete, create) of ASP.NET MVC applications? In all incoming and outgoing operations or operations whose execution is…
-
2
votes1
answer39
viewsA: How to call another action and return the value?
The values that are in the Teste2 action, move to Teste1 action with variable value, this is possible? Possible, it is, but this is bad practice. Note that the return of Teste1 and of Teste2 is a…
-
7
votes1
answer660
viewsA: Check if all items in a string are different?
By set theory, a data structure set does not allow repetition of elements. Therefore: >>> x = "abcdefga" >>> conjunto = set(x) >>> conjunto {'f', 'c', 'g', 'b', 'd', 'e',…
-
1
votes3
answers4236
viewsA: How to open . txt files in Python?
To flag "r" error if the file does not exist. To avoid error, use "a+": f = open('ficheiro.txt', "a+") See more here.…
pythonanswered Leonel Sanches da Silva 88,623 -
10
votes2
answers8828
viewsA: After all, what is the function Repr in python for?
__repr()__ serves to represent an object as a string. It does not need to be called directly. Every time Python needs to solve an object like string, __repr__() will be called automatically. Various…
-
0
votes2
answers431
viewsA: Web system accessed by various companies appsettings
I’ve been seeing the question Databases for different customers, not if it would be the right thing to do. It depends. If you want to separate databases by company, it is, but it doesn’t seem to be…
-
1
votes1
answer345
viewsA: Problems when mapping Entity Framework database
You can’t do this: HasRequired(x => x.Correspondente) .WithMany(x => x.Enderecos) .HasForeignKey(x => x.ReferenceId); HasRequired(x => x.Cliente) .WithMany(x => x.Enderecos)…
-
5
votes4
answers69
viewsA: How to convert fields to a line with string?
Whereas the number of fields will increase, use Reflection: public override string ToString() { string retorno = ""; foreach (var campo in this.GetType().GetProperties(BindingFlags.Instance |…
c#answered Leonel Sanches da Silva 88,623 -
6
votes3
answers3072
viewsA: Provide file download from server
Thus: public FileResult Download(int id) { var caminhoDaImagem = /* Aqui você usa id que vem por parâmetro pra fazer alguma operação que seleciona o caminho da imagem de algum lugar */ byte[]…
-
0
votes1
answer326
viewsA: How to use Validationmessagefor in Dropdownlistfor?
Some things are still missing. This error you had means that the form information did not go through validation, the View return filled with errors and all Dropdowns need to be loaded again. As they…
-
11
votes2
answers17350
viewsA: Minimum bit amount required to represent decimal numbers
To calculate the number of bits, you can use Log2(X), rounded up: Log2(4095): 11.9996477365, ie, 12; Log2(65534): 15.9999559718, ie, 16; Log2(42319): 15.3690179165, i.e., 16.…
-
4
votes1
answer708
viewsA: One of the fields must be required - Dataannotation
It is not with decoration by attributes that you will solve. Implement IValidatableObject in the Model: public class MeuModel : IValidatableObject { ... [Display(Name = "CPF")] public string CPF {…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
0
votes1
answer180
viewsA: Add parameter using Pagedlist in logging detail and page links
The documentation of Pagedlist or that of the X.Pagedlist (the latest version) suggests something like this: @Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new { pag = page…
-
0
votes1
answer69
viewsA: Vagrant - VM does not go up when adding a forwarded_port
It is a bug of Vagrant 1.9.3. The recommendation for now is to downgrade from Vagrant to version 1.9.2. For Windows and Linux, use this link.…
-
0
votes1
answer469
viewsA: Entity Framework 6, many X many relationship and Scaffolding
I have tried in numerous ways indicated here on this site. I tried this way here and creating the associative class manually, but in scaffolding the Entity does not generate the relation in the…
-
2
votes1
answer23
viewsA: Relationship 1:N using EF using Data Annotationion
As doubt clarified by comment, there is no problem with the mapping itself, which is correct. When bringing the stages of a championship, it is recommended to rush the load using .Include(): var…
-
2
votes1
answer162
viewsA: What does everything in this method do? (Mirror Audit in Entity Framework)
What is Changetracker.Entries()? Are the entities that context observed that have some change from the original database record. What makes this line var tipoTabelaAuditoria =…
-
3
votes1
answer278
viewsA: How to avoid blocking requests?
I don’t know if this is some kind of configuration that should be inserted into the IIS or the application. Have you answered yourself in this comment here: I’m not using asynchronous methods in the…
-
1
votes1
answer82
viewsA: Delphi 2006 - 3 layers - Tsocketconnection - Tclientdataset
If the idea is to collect Socket errors silently, I would use the Log4delphi. If the idea is to take at the application level, there are paid tools like Eurekalog and Madexception who does it for…
delphianswered Leonel Sanches da Silva 88,623 -
1
votes1
answer287
viewsA: Error saving Entity framework
When I try to add a Client, Add throws an error saying that the User property has the Name field that is required. However, I am setting the Userid and not the User (for a very noble reason: setting…
-
0
votes1
answer55
viewsA: T4 to SQL . NET error
Line 104 of the file C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToSQL10.tt contains: foreach (AssociationSet associationSet…
-
2
votes2
answers1601
viewsA: Use more than one template in View - C# MVC
To register a mobile phone, I need to select a brand for it, ie two models in a view. Wrong. If the Celular belongs to a Marca, that is to say: public class Celular { [Key] public int CelularId {…
-
4
votes1
answer230
viewsA: Filter Postgresql Information on Windows Forms screen using Entity Framework
Yes. Use [Column]: [Column("Código Cliente")] public int ClienteId { get; set; } [Column("Data de Nascimento")] public DateTime DataNascimento { get; set; } The question title should be "how to…
-
3
votes2
answers930
viewsA: Understanding the documents of a SOAP web service
The translation of the WSDL takes place as follows: Tags <wsdl:operation> are translated as methods that can be called. They usually have two components: <wsdl:input> and…
-
0
votes2
answers126
viewsA: View Not Updatable in SQL Server
The most performative form I know is: CREATE VIEW MinhaView AS SELECT TOP 100 PERCENT Coluna1, Coluna2, Coluna3 FROM tabela WITH CHECK OPTION
sql-serveranswered Leonel Sanches da Silva 88,623 -
4
votes1
answer241
viewsA: C# class as parameter in SQL Server
The easy and simple way is by using Dapper. Running Stored Procedure for Selection var cliente = connection.Query<Cliente>("PROC_Select_Cliente", new {ID = 1}, commandType:…
-
2
votes1
answer351
viewsA: How to use inheritance and polymorphism when passing a JSON to a MVC C#Controller?
Basically using a Model Binder written by you and a little Reflection: public class ClienteModelBinder : DefaultModelBinder { protected override object CreateModel(ControllerContext…
-
0
votes1
answer179
viewsA: resize an image and then save to mysql
There’s a package for that, but I guess it’s not what you want. There’s another way to do it that’s simpler, using WebImage, but the quality is lower. Example: using System.Web.Helpers; [HttpPost]…
-
1
votes3
answers842
viewsA: Check two or more occurrences of a listed element (lambda/Linq)
Another way to solve: if (listCard.Count(x => x == card) > 1) continue;
-
6
votes2
answers7285
viewsA: How to paste clipboard text into vim?
How do I paste text from the clipboard? I usually use the key p to paste after cursor. Shift + p to glue before (or P, capital). How to select and copy something from vim itself? Without using…
vimanswered Leonel Sanches da Silva 88,623 -
2
votes1
answer255
viewsA: Asp.Net Razor with Json
From what I could observe one of the things that "must" work to get the expected result is to work with Json (so far so good) as if my application was a Web API - I’m sure? Even better: working with…
-
3
votes1
answer1215
viewsA: Configure Firefox webdriver in Selenium
Use FirefoxProfile to configure your Firefox before instantiating browser: from selenium import webdriver import os firefox_profile = webdriver.FirefoxProfile()…
-
5
votes1
answer360
viewsA: How to check if the application shortcut exists on the Desktop, if there is no create
You can check if any of the icons have the target you are searching for. The following function may be useful. uses Winapi.ShellAPI, Winapi.ShlObj, System.Win.ComObj, System.Win.Registry,…
delphianswered Leonel Sanches da Silva 88,623 -
4
votes1
answer54
viewsA: Doubt with XML file creation
I love your idea, but the approach is not good. Use Extensions to the XmlWriter that will work better: public static void testeGerarXml() { using (var xml = new…
-
1
votes1
answer900
viewsA: How to set a session timeout on the web.config
You are confusing expiration of session data with login session, and they’re not the same. The performative way to do this is by defining an attribute that checks whether the SessionStore whether or…
-
2
votes1
answer149
viewsA: How to customize "Confirmation window"?
That’s more of a Javascript question than an ASP.NET MVC question, but come on. The idea is to have it in your <form>: <form onsubmit="return confirm('Tem certeza?');"> That is to say:…
-
5
votes3
answers603
viewsA: Problem sending model to controller
The right thing would be: public class Pessoa { public virtual long Id {get; set;} public virtual string Nome {get; set;} public virtual ETipo Tipo {get; set;} public virtual List<Cliente>…
-
2
votes1
answer57
viewsA: Fix value still inside the View
Using the good old <form>: @Html.BeginForm() { ... } As it is a collection of records, it is good to use the package Begincollectionitem. With it, each of these objects can be represented by a…
-
3
votes1
answer1020
viewsA: Mysql connection does not appear in Data Connection
Possibly lacked a plugin. It is also in the Mysql Installer:…
-
2
votes1
answer297
viewsA: Entity - Multiplicity Constraint violated
The context is understanding that pessoa is a new Person, not an existing person. It’s better to do it like this: var pessoa = db.Pessoas.Include(p => p.Ocorrencias).Where(...); var ocorrencia =…
-
3
votes2
answers439
viewsA: Entity Framework | Double property that allows null
Maybe you’re not forcing the notation to double: ocorrencia.Avaliacao = 5.00D;
-
14
votes4
answers977
viewsA: Separate repeated values in a list
By mathematical definition, a set is a structure in which each element appears only once. In C#, a set is represented by HashSet<T>. Generating a HashSet<int> from your list, you will…
c#answered Leonel Sanches da Silva 88,623 -
3
votes1
answer65
viewsA: Entity Framework - Object exclusion with relationship
You did not charge Pessoa. You need to load the object for the context to observe it: var Ocorrencia = db.Ocorrencia .Include(o => o.Pessoa) .FirstOrDefault(c => c.id == id); Ocorrencia.Pessoa…
-
3
votes2
answers278
viewsA: Special character encoding before going to the SQL database
You don’t need any of this. Just mark the Model or Viewmodel with [AllowHtml]: [AllowHtml] [DataType(DataType.MultilineText)] public String MeuTextoHtml { get; set; }…
-
13
votes3
answers17994
viewsA: What is the Difference Between HTML.Actionlink vs Url.Action?
Reading some tutorials of ASP.NET MVC I found these two helpers being used to do basically the same thing, which was to direct the user to a new view. That’s not what they do. Their function is to…
-
4
votes1
answer71
viewsA: Codefirst Entity Framework database, 1-0.. 1, 1-N
Let’s start with TagAnalogico: [Table("TagAnalogico")] public class TagAnalogico : Tag { // Você precisa identificar ou aqui ou na classe ancestral a chave. [Key] public int TagAnalogicoId { get;…
-
1
votes1
answer149
viewsA: The Viewdata item that has the key 'Fabricanteid' is of type 'System.Int64' but must be of type 'Ienumerable<Selectlistitem>
Your problem is a typo, here: ViewBag.CategoriaId = new SelectList(context.Categorias.OrderBy(b => b.Nome), "CategoriaId", "Nome", produto.CategoriaId); ViewBag.CategoriaId = new…
-
1
votes1
answer613
viewsA: Javascript load Partialview passing a Model
This isn’t gonna work: var modal = new Custombox.modal({ content: { effect: 'blur', target: @Html.Partial("_Unidade", Model), } }).open(); You need to call @Html.Partial before the Javascript…