Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
9
votes3
answers6925
viewsA: How to send 2 Controller objects to the View in C#?
Create a Viewmodel: public class PessoaContatosViewModel { public PessoaAplic Pessoa { get; set; } public ContatoAplic Contato { get; set; } } Use: // Controller // Pego os dados do BD e salvo no…
-
1
votes1
answer58
viewsA: How do I recover filters from a query?
Yes, it is possible. Thus: var query = (from produto in produtos where produto.Id < 3).AsQueryable(); var predicado = query.Expression;
-
5
votes2
answers141
viewsA: Dynamic declaration in attribute property
The problem is that attributes do not accept dynamic object initialization. There are two alternatives: 1. Mark attribute with adapter type [MicroEntity( TableName = "mdl_course",…
-
12
votes2
answers10850
viewsA: What is the main difference between int. Parse() and Convert.Toint32()?
Playing Int32.Parse() in the Reflector: public static int Parse(string s) { return System.Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo); } Which in turn calls: internal…
-
3
votes2
answers676
viewsA: HTML element inside an Actionlink
The most interesting way I found to solve the problem is by creating my own extensions for the HtmlHelper. For your case, that you want to use the Fontawesome in the link, the code below solves:…
-
11
votes1
answer3277
viewsA: How does the Linq Aggregate() extension method work?
I already answered that here, but not specifically on Aggregate, then I’ll isolate the part of the answer that matters. The explanation is within the concept of using the Entity Framework, but you…
-
0
votes1
answer116
viewsA: EF6 and NPGSQL : Foreign key breach error
When it comes to including a "persona", I purposely specify a country that is not registered, generating a foreign key violation error of Postgres. But the RU should not do the validation before?…
-
1
votes1
answer194
viewsA: Modal pagination using Url.Action
If I were you, I’d change everything to GET. Abandoaria the POST, even because forms accept the GET. To preserve parameters, I recommend implementing the following extension to the UrlHelper: using…
-
2
votes1
answer73
viewsA: Summary in classes and methods
How important the use of <summary> in methods and classes? Not only document your code elements, but also serve as help when using Intellisense (Ctrl + Shift + Space, the description of…
-
9
votes2
answers323
viewsA: What is the @ in a view and controller for?
What is the purpose of @ (arroba) both in controller how much in the view? In the View, indicates to the Razor engine that the following code is to be interpreted by .NET. Can be used on a line: @if…
-
2
votes1
answer163
viewsA: Configure Scaffold to generate classes
Yes. First you need to generate one template for their Viewmodels. There’s a Nuget package that has several templates as an example. Once done, modify a template View (save with another name) and…
-
5
votes2
answers9136
viewsA: Create static Selectlist and pass a selected item to the View
@Html.DropDownList becomes quite limited when you send a SelectList ready. Particularly, I prefer that the View pile that DropDownList to me as follows: @Html.DropDownListFor(model =>…
-
1
votes1
answer1707
viewsA: Ordering a second list according to the ordering of the first list
If I understand, this is what you want: primeira_lista = lista[0] segunda_lista = lista[1] tuplas = [(indice, valor) for indice, valor in enumerate(primeira_lista)] # print(tuplas)…
-
0
votes3
answers565
viewsA: Repeat LEFT JOIN with other parameters in the same query
You can use more than one JOIN: SELECT pai.nome, count(distinct filho.id) as somahomem, count(distinct filho2.id) as somamulher FROM pai LEFT JOIN filho ON pai.id = filho.idpai AND filho.sexo = 'm'…
-
3
votes1
answer549
viewsA: How to update only the model in ASP.NET MVC?
Following @Rsinohara’s comment, the way is through Ajax at View. In a writing system, I use a set of methods implemented using jQuery: function TrocarCidades(id, estadoId) {…
-
1
votes2
answers336
viewsA: Creation of ASP NET MVC reports
Excel The best component I’ve found so far is called Epplus. His Nuget package is here. Here on the site we have some questions answered about it. I recommend reading them to have idea of…
-
1
votes1
answer266
viewsA: Doubt with Entityframework (Migration)
This here was generating ambiguity of names: namespace ControleInterno { class ControleIntContexto : DbContext { ... } } How did you remove the context of namespace right from him…
-
1
votes1
answer762
viewsA: How to pass the parameters of a view to two different ASP NET MVC actions
I don’t think you need two methods to generate the report. You might as well include one more parameter in the Controller to return either in screen or in PDF: public ActionResult Relatorio(string…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
2
votes1
answer1371
viewsA: checkbox + Model + Controller. How to pick up selected rows?
It is not good practice to leave in the same Action very different functions, such as assembling a Viewmodel and persist a new user. The correct thing would be to do the following: public…
-
8
votes3
answers576
viewsA: Session Limitation to Save Data
The average of records returned is 600, it’s too much for a Session? Not. Sessions theoretically have no storage limit. Would there be some other better way to save this data? Yes, on a key-value…
-
4
votes2
answers1570
viewsA: Which PIP version should I use?
I must use pip3 for Python3.x or I can also use Pip without any problem? The version of pip works with any version of Python, in theory. Python usually already comes with a pre-configured Pip…
-
3
votes1
answer76
viewsA: How to block menu buttons, when a form has not been saved yet, is it possible?
The best alternative is using jQuery: $(window).bind('beforeunload', function(){ return 'Are you sure you want to leave?'; }); Put this inside the tags <script> and </script>: This…
-
1
votes2
answers1380
viewsA: Capture Machine Identification with C#
The solution is to identify only the machine. The problem is that the best way to do this would be to get some hardware information, such as the MAC address of the network adapter or even some…
-
2
votes1
answer1485
viewsA: Create tabs dynamically in excel
Yes, there is. I assembled the Helper below that does it. It is based on the package Epplus. Possibly you will have to change this Helper a little to work properly for your case. Note that he uses a…
-
1
votes1
answer97
viewsA: How do I not lose the data included in Claims in the revalidations of Cookies?
The problem with revalidation is that you don’t store session information anywhere. It’s important to understand that Claims are different from session data. There are two things you can do:…
-
2
votes1
answer122
viewsA: View 3 Models in a View
You didn’t pass the Models of possibilities in Partials. It won’t work like this: <div class="form-group"> <div class="col-md-2">FORNECEDOR</div><div…
-
3
votes1
answer87
viewsA: Replacement for the Fluent API
I’m guessing the entity is called OrdemCompra: public class OrdemCompra { ... public int UsuarioCadastroId { get; set;} ... public virtual Usuario UsuarioCadastro { get; set; } } And in Usuario:…
-
2
votes2
answers83
viewsA: Persistence using Fluent API
Ideally you do not use the Fluent API, rather an associative entity: public class Cliente { /* Propriedades do Cliente */ public virtual EnderecoCliente EnderecoCliente { get; set; } } public class…
-
0
votes1
answer104
viewsA: Get currency quotes from date
By Webservice I know Currencyconvertor from webservicex.net. Just import the Web reference. By REST API There is the Openexchangerates.…
-
3
votes1
answer1261
viewsA: Include Method - MVC - working with data insertion in two tables
First of all it’s important to know that Usuario has cardinality 1 to N with UsuarioP, otherwise it is impossible to answer this question. 1) How can I instate it in class without being in the way…
-
5
votes2
answers109
viewsA: Questions about Fluent API relationship for EF 5
There is nothing wrong with your code. The mapping is perfect. There is, yes, something wrong in the way you are using. Usuario has N UsuarioP (cardinality 1 to N). That is, you will also have N…
-
1
votes1
answer27
viewsA: MYSQL - Select not working properly
This sign: !=, does not exist in the default SQL syntax. There is even an entry in the Mysql manual with this, but the recommended, even for approaching SQL ANSI, is to use <>, common to all…
mysqlanswered Leonel Sanches da Silva 88,623 -
1
votes2
answers125
viewsA: Edit Image in database when field is empty
There’s a lot of things wrong here: funcionario.Foto = funcionario.Foto; funcionario.Freguesia = funcionario.Freguesia; funcionario.Concelho = funcionario.Concelho; This assignment doesn’t make any…
-
2
votes1
answer446
viewsA: How to convert Json to Object where the column name is a variable number using Httpresponsemessage
The JSON.NET package does this for you. Example: dynamic d = JObject.Parse(response.Content.ReadAsAsync<RootObject>().Result); The documentation is here…
-
1
votes2
answers673
viewsA: How to return to the previous page by Handleerrorattribute?
The correct way to treat entity validation errors from context is by Controller: public ActionResult MinhaAction(MeuModel model) { try { db.PersonalDetails.Add(model); db.SaveChanges(); } catch…
-
1
votes2
answers673
viewsA: How to return to the previous page by Handleerrorattribute?
This answer proposed to follow a path suggested by the author of the question, which is not correct for the case. Validation errors should be treated differently from application errors, because…
-
1
votes1
answer148
viewsA: Sending post to Actionresult via knockout
Well, that’s not going to work. Um ActionResult moves the page request directly. Making the request by Ajax, what will be returned will be a View, which will be encapsulated by Ajax. For this case,…
-
1
votes3
answers339
viewsA: Connection to the bank is open in static method?
Because it is a static class and has a database connection, this connection is open at all times or is only opened when I call MinhaClasse.Salvar(Item);? Not. The Dispose of DbContext calls the…
-
2
votes2
answers777
viewsA: C# Regular expression for string and Guid validation
I would like to validate a string by checking that it only has {[a-z], [A-Z], [0-9], '-'} It can be done like this: var re = new Regex("[A-Za-z0-9\-]+"); var valido = re.Match("Minha String…
-
0
votes2
answers296
viewsA: validation for Partialview
I don’t know how you’re doing Viewmodel, but it is necessary to note [Required] in properties that cannot be empty for correct validation: [Required] public int Dias { get; set; } Optionally, you…
-
4
votes2
answers571
viewsA: Pass generic model to controller
I still don’t understand what you want to do, but the View accepted by default the following: @model dynamic I mean, you can always pass anything. Of course this has consequences. You need to keep…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
3
votes1
answer275
viewsA: Jsonresult return error
You have a circular reference problem. The JSON serializer attempts to serialize an entity A, which references an entity B, and which in some way refers back to A. There’s already an answer to that…
-
5
votes1
answer235
viewsA: Updating collections with Entity framework
Until today I have not found an answer that would explain me this properly, so I created an algorithm that I use for these cases. Suppose an entity Cliente that has N ClienteTelefones, and that this…
-
3
votes1
answer727
viewsA: Fundamental principles REST
What this interface would look like (based on the image)? It depends on your system, but usually a system that implements the REST API (Web API 2 is one of the frameworks that implements the…
-
0
votes1
answer344
viewsA: MVC Hidden Field Encryption - How to decrypt more than one Server-side property
I’ll put the code to the second form: [ValidateAntiModelInjection("property1","property2")] public ActionResult (MinhaModelDTO Model) {...} Stay like this: public class ValidateAntiModelInjection :…
-
2
votes1
answer237
viewsA: Remove EF dependencies without using the Myconfiguration class
Depends. The Entity Framework requires at least one data access provider. As in this case you are using SQL Server Localdb for database access, the Entity Framework needs this dependency with…
-
1
votes2
answers337
viewsA: No Entity Framework provider found for ADO.NET provider
Make sure your layers reference the default . NET library System.Data. That’s where the namespace System.Data.Sqlclient.…
-
10
votes3
answers261
viewsA: What is the advantage of using the Set<> method?
The advantage actually exists when you want to implement generic behavior in some function of your. For example, you want to write a method that brings only the first 10 records of any DbSet. You…
-
1
votes1
answer94
viewsA: How to implement jQuery Filer Plugin?
Still need to install the Backload. It does asynchronous management with Javascript plugins, be it jQuery Filter or jQuery Upload Plugin. To learn how to use Backload, open a new project and install…
-
1
votes2
answers2145
viewsA: Error with System.Web.Webpages.Razor.dll
You are using packages of mixed versions of MVC. Apparently your project was started in version 4, and now you want to use packages of version 5. Make a update complete your project, opening the…
asp.net-mvcanswered Leonel Sanches da Silva 88,623