Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
1
votes2
answers464
viewsA: Save Objects Relationship Only - Entity Framework
Your modeling is wrong. See corrections below: public class A_B { [Key] public int Id { get; set; }; // Use propriedade, não campo. [Index("IUQ_AB_AId_BId", IsUnique = true, Order = 1)] public int…
-
1
votes1
answer107
viewsA: Kendo UI Scheduler
Kendo UI is not compatible with several versions of jQuery. Events like this show that something in jQuery events is broken. Check here which version you can use. Beam your packages.config to use…
-
2
votes2
answers437
viewsA: Putting social media buttons on the site
Modern browsers have restrictions when downloading JS files from other sources. You can save the file in your solution and use it this way: <script type="text/javascript"…
-
1
votes1
answer249
viewsA: Reuse of Python functions
Do the following: import random class teste(): def __init__(self, x = 0): self.x = x self.aleatorio() def aleatorio(self): self.a = random.randint(0,100) return self.a class verificar(): def…
python-2.7answered Leonel Sanches da Silva 88,623 -
5
votes2
answers1349
viewsA: How to convert a nullable int to common int
Normally, the following technique solves: public HttpResponseMessage Metodo(int? variavel) { var variavelNaoNula = variavel ?? 0; var bla2= blablabla.Metodo(variavelNaoNula, DataContext); }…
-
3
votes3
answers525
viewsA: How to insert an existing record into the Entity Framework?
If the record needs to be replicated, i.e., reinserted, you cannot reinsert with the same primary key value. You need to create new objects from objects that already exist. That is: var…
-
1
votes2
answers1386
viewsA: Access client-side biometric reader - ASP.NET MVC - WEBFORMS
Any suggestions on how I can do this? Yes, developing an extension for Google Chrome, or for Firefox, or to other browsers you want. The problem is that your biometric reader is on the client and…
-
3
votes1
answer106
viewsA: Python connection Webhook problem
The mistake is clear, caused by something treacherous: IndentationError: unindent does not match any outer indentation level In this line: File "C:\Users\fabio\dsa-bot-fabio\app.py", line 37 if…
-
4
votes1
answer116
viewsA: Displaying total connections to a certain IP address
Assuming the file saida.txt, I would do so: with open('saida.txt') as f: linhas = f.readlines() soma = 0 for linha in linhas: soma += int(linha.strip().split(" ")[0]) print(soma)…
-
4
votes2
answers57
viewsA: What function do I use to return or show all the equal numbers in a list of 20 numbers?
Thus: import collections print([item for item, contagem in collections.Counter(n).items() if contagem > 1]) Or so: print(set([item for item in n if n.count(item) > 1]))…
-
0
votes1
answer29
viewsA: Display an Enumdropdownlistfor as a condition
I would do so: @if (UsuarioNaoQuerApresentarOrientacaoSexual) { @Html.Hidden(model => model.OrientacaoSexual, OrientacaoSexual.NaoInformado) } else { @Html.EnumDropDownListFor(model =>…
-
21
votes3
answers511
viewsA: What is the most recommended "Try" or "if"
What’s the difference between using if and Try Well, they’re very different from each other. if serves to make a conditional flow. try ... catch serves to catch errors (or exceptions, in the correct…
-
2
votes1
answer45
viewsA: The interface freezes while loading an event
About calling a Process in an asynchronous way, you will have to use a code like this: public static async Task<int> RunProcessAsync(string fileName, string args) { using (var process = new…
-
1
votes1
answer168
viewsA: My controller can’t find the view
It’s some nomenclature problem. From the photo you took, I don’t see the Action Email in his EmailController. Try creating the Action and try again.…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
2
votes1
answer210
viewsA: ASP.NET Web API post Byte[]
But still the question remains, how to give a Post in a model with a type property byte[]? I wanted to understand why you had one Timestamp in client, and it is not even a property that should be…
-
4
votes1
answer3993
viewsA: Webbrowser in C# using Chrome
Yes, whereas you are using Windows Forms, this package can be ideal. Instructions on how to use are here. There is an example of use here.…
-
5
votes3
answers1815
viewsA: How to start a range from 1
Just increment the counter: alunos = int(input("Digite quantos alunos você deseja cadastrar: ")) notas = [] for i in range(1, alunos + 1): nota = input("Coloque a nota do aluno " + str(i) + ":" )…
-
5
votes1
answer3139
viewsA: Python integration with C#
Compile everything in Ironpython. You have version 3 here. Look for programming using classes, so . NET recognizes. Then just play in C#. An integration guide is here.…
-
5
votes1
answer65
viewsA: How to calculate the time of a LINQ query?
You can use Miniprofiler: using StackExchange.Profiling; var profiler = MiniProfiler.Current; using (profiler.Step("Minha query")) { var alguma coisa = /* Coloque sua consulta LINQ aqui */ }…
c#answered Leonel Sanches da Silva 88,623 -
7
votes3
answers1480
viewsA: How to make a query through LINQ ignoring accents?
You can only do that if you define the COLLATION column (or table, or bank) before. There are some ways to do this. One of them is defining a baseline initializer, thus: public class…
-
3
votes1
answer41
viewsA: EF6 - Rushed load bringing less aggregated data than database data
All this code is useless: public ClienteEntity(string nome, IList<EnderecoClienteEntity> enderecos) { Nome = nome; _enderecos = new List<EnderecoClienteEntity>();…
-
2
votes4
answers54
viewsA: Doubt about the use of the VS2015 SPA Template
You can also use a nominated argument: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> EnviarEmail(string submit) { switch (submit) { case "Enviar": ...…
-
1
votes1
answer52
viewsA: Views Index, List views show date in wrong format
Possibly your Windows is in English, which makes the configuration of date formats be in American format. In the archive Web.config, add the following: <configuration> ... <system.web>…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
1
votes1
answer54
viewsA: Log data through different View
The path to very long forms is using tabs. To View can have several fields and the user fills each tab with the categorized fields. There is also the jQuery Steps, if you want to do Wizard face. Tem…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
3
votes2
answers598
viewsA: Entity Framework - When editing, "db. Entry(Category) fails. State = Entitystate.Modified;"
Don’t take this the wrong way, but the solution to this is awful. The mistake happens because of this: //Eu inseri este trecho category.Created = db.Categories.Find(category.CategoryId).Created;…
-
6
votes1
answer4748
viewsA: Visual Studio Indentation Configuration
Go to Tools > Options > Text Editor > C# > Formatting > New Lines: Check or uncheck the options until you get the desired behavior.…
-
1
votes3
answers7999
viewsA: Update Error with Entityframework
The mistake means that cliente.Titulo does not yet exist in database, so Entity Framework returns a message saying that there are no objects with the Id passed in the object. Possibly the id is…
-
5
votes1
answer72
viewsA: How to capture Stackoverflowexception
A more efficient method to capture the exception (and the Stack Trace all) is using the ELMAH. Also try to publish along with the system the file .pdb, so that you have in the messages captured from…
-
1
votes1
answer242
viewsA: How to create a webgrid with dynamic columns?
Something like that: @model IEnumerable<dynamic> @{ WebGrid grid = new WebGrid(source: Model, rowsPerPage: 5, canPage: true); List<WebGridColumn> cols = new List<WebGridColumn>();…
-
1
votes1
answer63
viewsA: Open Search Description (press tab to search)
You need to put the path of XML in the tag <head> of its application: <head> ... <link href="<%= Url.Content("~/Content/OpenSearch.xml") %>" rel="search" title="Pesquisa no Meu…
-
1
votes1
answer120
viewsA: Asynchronous Method Blocking Queue
Because ASP.NET MVC queues requests from a single client to not cause session variable conflicts. As the article explains, it is possible to implement a SessionStateStoreProvider that doesn’t stop…
-
1
votes1
answer40
viewsA: EF relationship from Foxpro migration, with composite key
The Entity Framework natively does not have this ability to intuit the type of the related table automatically, by using a column, for example. If I were you, I would do a job on SQL to improve this…
-
2
votes1
answer44
viewsA: Remove multiple protocol authentication
Insert in your Global.asax.cs the following: void Session_Start(object sender, EventArgs e) { if (Request.IsSecureConnection) Response.Cookies["ASP.NET_SessionID"].Secure = false; } Thus, their…
-
2
votes1
answer68
viewsA: How to add data using Begincollection and Partialviews
Starting with your edition: // GET: PontosDeColeta/Edit/5 public ActionResult Edit(Guid? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } // Estou modificando…
-
3
votes1
answer167
viewsA: Edit object, with related objects
This code is useless and is causing your error: Titulo titulo = await db.Titulos.SingleAsync(t => t.TituloId == cli.ClienteId); db.Entry(titulo).State = EntityState.Modified; await…
-
2
votes1
answer77
viewsA: Error in Transactionscope
What causes this mistake? Note that here you use as parameter an aggregate class that has not yet been loaded (cliente.Titulo): Titulo titulo = await db.Titulos.Where(t => t.TituloId ==…
-
1
votes1
answer1000
viewsA: Recover image through path and display
About this code, I made some modifications to support my answer: public ActionResult enviaArquivo(UsuarioViewModel arq) { // Não use try ... catch em Actions. // O evento correto para interceptar…
-
0
votes2
answers700
viewsA: Add the results for x in range
You can do it like this: soma = 0 for k in range (5,10): soma += 2 * k ** 2 print(2 * k ** 2) print(soma)
pythonanswered Leonel Sanches da Silva 88,623 -
3
votes2
answers276
viewsA: Dropdownlist with Begincollectionitem
You didn’t define the ViewBag on the return of Partial. Naturally it will have zero reference error: public ActionResult NovaLinhaDeTipoDeLixo() { ViewBag.Lixo = db.TiposDeLixo.ToList(); return…
-
3
votes1
answer45
viewsA: How can I read custom Attributes without using reflection?
How can I read custom Attributes without using reflection? There’s no way. As the problem is the matter of speed, the speed preblema in Reflection is in the reading and definition of property…
c#answered Leonel Sanches da Silva 88,623 -
1
votes3
answers3523
viewsA: ASP.MVC error "cannot find resource"
You never access the View directly. The correct is to access Action of each Controller. For example, if I have one Controller called ProdutosController and a Action calling for Index, the route will…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
0
votes1
answer433
viewsA: Leave HTML.Dropdownlist() in Bootstrap style?
Apparently everything is right. I suggest another construction to better manipulate your Dropdown: @Html.DropDownListFor(model => model.countriesDiretorySelect,…
-
1
votes2
answers1143
viewsA: Create Javascript mask using jQuery
There are two points here: @Html.DisplayFor() and @Html.TextBoxFor(), or else @Html.EditorFor(). In the case of @Html.DisplayFor(), you can wear something like this: @Html.DisplayFor(modelItem =>…
-
2
votes2
answers72
viewsA: How to use an Array to draw elements?
If I understand, you just have to use Rnd(): With SerialPort1 .Write("AT" & vbCrLf) Threading.Thread.Sleep(1000) .Write("AT+CMGF=1" & vbCrLf) Threading.Thread.Sleep(1000) .Write("AT+CMGS="…
-
5
votes1
answer359
viewsA: Using EF and Dapper in the same project
Is there any way I can use both Orms in my project? because I liked the EF in the issue of mapping and Migrations because I use as Code First. Yeah, check it out: var query =…
-
1
votes1
answer61
viewsA: Validate Streamreader twice
As the questioner comments, there is a problem of Position when reading the file submitted by form: model.Arquivo.InputStream.Position = 0; This is because model.Arquivo.Peek() == -1 Which indicates…
-
1
votes2
answers730
viewsA: How do I checkbox Asp.net mvc database
The best way is defined Viewmodels: public class PlaylistViewModel { public Playlist Playlist { get; set; } public ICollection<UsuarioViewModel> Usuarios { get; set; } } public class…
-
11
votes8
answers2223
viewsA: Error: not all code paths Return a value
Because of that: if (leitor.HasRows) { while (leitor.Read()) { componente componente = new componente(); componente.ID = Convert.ToInt32(leitor["id"]); componente.NOME = leitor["nome"].ToString();…
-
2
votes2
answers271
viewsA: Problem running tasks with two buttons in the same form in c#
Apparently there’s nothing peculiar that makes the code work on the first button and it doesn’t work on the second. Anyway, I would slightly alter the invocation: private void button2_Click(object…
-
3
votes2
answers544
viewsA: Map Enum with search conditions
This question continues of this question here, that the answer has gotten a little dense even. The idea is now to better sift through the filtering technique I explained earlier. In the previous…