Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
1
votes1
answer60
viewsA: Problem - Linq SQL Server: Unwanted query in database when assigning value in a database derived field
There are a lot of weird things in your code. This is one of them: DataContext db = new DataContext(entity.Connection); It’s not clear what it is entity in your code. I believe it’s another context.…
-
1
votes2
answers294
viewsA: Request ajax accessing already included scripts
In ASP.NET MVC, Scripts should not be placed in Partial Views for the simple fact that Partial Views can be reused in various parts of your code, causing a strange behavior of Scripts. The correct…
-
3
votes2
answers728
viewsA: Simultaneous client side and server side requests
If I use N ajax requests simultaneously, I’m still handling these requests synchronously on the server? It depends on the server implementation. Normally, the response method has something like…
-
1
votes2
answers212
viewsA: Electron Configuration of an Element of the Periodic Table
using System; using System.Collections.Generic; namespace Eletrons { class Program { static void Main(string[] args) { // Passo 1: Detectar qual a última camada cheia. int z = 53, i = 0, somaCamadas…
c#answered Leonel Sanches da Silva 88,623 -
2
votes2
answers210
viewsA: Query performance with date range
Case 1: CAMPO_DATA has no index The execution plan will be on top of the whole table (TABLE SCAN). For both consultations, the time will be the same. Case 2: CAMPO_DATA has index The execution plan…
-
1
votes1
answer157
viewsA: Remove Xnamespace in Xelement c#
This is because you are forcing the name of namespace as media: new XAttribute(XNamespace.Xmlns + "media", ns), Switch to: new XAttribute(XNamespace.Xmlns, ns), This should generate the following…
-
0
votes2
answers80
viewsA: Serialize xml output to class
Apparently it’s all right. To serialize, use the following: var emailViewModel = new EmailViewModel { cnt = 7469; emails = new emails { items = new item[] { new item { to_email = "[email protected]",…
-
3
votes1
answer493
viewsA: aspx page running on Asp net mvc
This answer is expected to undergo a number of changes in the coming days, in line with the subsequent doubts of the questioner on specific aspects of its application. It may be that other questions…
-
0
votes1
answer4745
viewsA: Reference System.Web.Webpages.Razor, Version=1.0.0.0. The system cannot find the specified file
In your file Web.config, check the following entry: <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> ... <dependentAssembly>…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
1
votes2
answers942
viewsA: Multi Language ASP.NET MVC
The most succinct way is the first, with a few increments: public class Livro { [Key] public int LivroId { get; set; } [Required] public String Titulo { get; set; } public String Subtitulo { get;…
-
6
votes3
answers33401
viewsA: Select 1 record of each ID based on the last date
Altering a little your subselect you easily reach the desired result: SELECT TQ.[COD_VENDEDOR], TQ.[VAL_META], TQ.[DAT_ATIVACAO] FROM [dbo].[TB_META] TQ WHERE TQ.DAT_ATIVACAO = (SELECT…
-
19
votes3
answers51028
viewsA: Regex - Special Character Removal C#
I would use a simple regular expression that brings only letters and numbers: Regex.Replace(minhaString, "[^0-9a-zA-Z]+", "");
-
2
votes1
answer351
viewsA: Change language in the database during a query
The easy way is applying CONVERT and specifying the desired format as the third argument. In your case, code 105: SELECT CONVERT(VARCHAR(10), GETDATE(), 105) It will generate something like:…
-
0
votes2
answers1799
viewsA: jQuery Mask Plugin does not format the number properly
There’s a question of mine in which I try to put this mask as an attribute of Model, but to this day I have not arrived at the ideal solution. This answer is the one that comes closest to solving…
-
0
votes2
answers1007
viewsA: Data validation with mvc Asp.net (edition)
RemoteAttribute expecting a JsonResult, and not a ActionResult. Anything other than true it interprets as an error. It may be a misinterpretation. public JsonResult Unico(string email) { try { int…
-
0
votes3
answers269
viewsA: How to reduce the capture of groups in a regular expression?
I’ve simplified your expression a little bit to only take the internal groups. I don’t know if the goal is to take a loan by phrase, but what I got was this::…
regexanswered Leonel Sanches da Silva 88,623 -
1
votes2
answers91
viewsA: Visual Studio 2013 only opens 2012 projects
In Visual Studio 2013, ASP.NET only uses MVC5, so it only has one option: In the Visual Studio 2012 option, there is also retroactive compatibility for MVC4 at most.…
-
3
votes1
answer219
viewsA: Multitenancy application and structure
Column separation DBA View and Performance The amendment will always require a composite index, which is larger and slower than the index based on only one column. Security It is the most insecure…
-
1
votes2
answers180
viewsA: How to produce JSON in the format that Flot expects?
When defining his data, make sure to pass the return of Controller within the Javascript method JSON.parse(): ... data: JSON.parse(retorno), ...…
-
1
votes1
answer604
viewsA: Problem updating database data using LINQ to SQL
That’s not how you use the Attach. First you need to load the object into its context, then modify it, and then you use the Attach: protected void Salvar() { // TB_CLIENTE_CLI cliente = new…
-
5
votes1
answer1287
viewsA: Security and authorization using Roles
Part of the answer that I will describe here begins in this other answer I made, explaining the whole scheme of Membership topology. Skipping to the part that matters, implement the following: 1.…
-
0
votes2
answers1013
viewsA: C# MVC EF5 delete relationships
I believe the fact that you’re sending an instruction to the Controller to which the association record belongs may be the complicator. The solution I’m going to pass is possibly quite different…
-
5
votes1
answer611
viewsA: Dataannotation validating property with Javascript plugin. ASP.NET MVC
This here: @Html.HiddenFor(model => model.IdNews) Does the ModelState try to validate the key IdNews, which has no value in the Action Create. Remove the hidden and test the validation again.…
-
1
votes2
answers1050
viewsA: Orphan records , checking in another table
It must be because you repeat the records. To find out which product Ids no longer exist, use: select distinct int_IDProduto from tbl_fotos where int_IDProduto not in (Select int_ID from…
sql-serveranswered Leonel Sanches da Silva 88,623 -
1
votes1
answer388
viewsA: Create registration pattern with C# UI repository
I would do something using Generics: public interface IComum<T> where T: class, IModeloDeDados { IEnumerable<T> Selecionar(); IEnumerable<T> Selecionar(IEnumerable<Operador>…
-
1
votes2
answers211
viewsA: Getting Foreign Key value - Object Reference not set to an instance of an Object
Change: <td>@item.Usuario.Nome</td> For: <td>@(item.Usuario != null ? item.Usuario.Nome : "")</td>
-
3
votes1
answer1120
viewsA: Modal de Confirmação
It’s missing inside your form the Id of the record to be deleted. Modify your View to the following: <div class="modal-body"> Apresente pessoalmente o comprovante de: @Html.DisplayFor(model…
-
1
votes2
answers1637
viewsA: Query SQL with 2 subselects for query lambda (or Linq)
This is because Select brings a field that is not exactly a IEnumerable. Contains exists only for IEnumerables. First, replace the first two Select for SelectMany (bringing together all the elements…
-
2
votes1
answer41
viewsA: Maintenance and recovery of service Urls
However, in DLL I have only one app.config file and it does not support Transformations. Yes. Only install the following extension in your Visual Studio:…
-
1
votes1
answer188
viewsA: Visual Studio keeps giving error in the ASP.NET MVC 5 project
If you are using Visual Studio 2012, please install the following package to support ASP.NET MVC5: https://www.microsoft.com/web/handlers/webpi.ashx/getinstaller/WebNode11Pack.appids…
-
2
votes1
answer108
viewsA: How to make a pager without a gridview?
Use the following package: https://www.nuget.org/packages/PagedList.Mvc/ Use: public ViewResult Index(int? pagina) { var produtos = contexto.Produtos; //traga todos os produtos aqui var…
-
1
votes3
answers1018
viewsA: Serialize XML for REST API with Correct Accent
To work, I had to change the serializer. Jettison didn’t work at all. I switched to Jackson and it worked: import java.text.ParseException; import java.text.SimpleDateFormat; import…
-
3
votes2
answers173
viewsA: Is having two dbContext for the same Connection string considered bad practice?
Yes. A context not only controls the loaded objects, but their states and all changes in records made within it. Loading these objects in separate contexts, changes made to the same record for both…
-
2
votes1
answer1682
viewsA: Create Roles to Hide/Show Menu
Like assigning which users are administrators? Using Roles. For example: @if (User.IsInRole("Administrador")) { ... } How to create a controller identifying which user is logged in (I use windows…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
1
votes2
answers1073
viewsA: Concatenate table name loop sql server
declare @i int set @i =1 while @i < 5 begin INSERT INTO TABELA VALUES('tabela' + CAST(@i AS VARCHAR)) set @i = @i + 1 end
-
0
votes3
answers3089
viewsA: Publication of MVC 4 site on IIS is giving error
Install MVC support on the server: http://www.asp.net/mvc/mvc5
-
1
votes2
answers133
viewsA: Loop Loop C# Asp components
Use a generic function: private IEnumerable<T> GetControlList<T>(ControlCollection controlCollection) where T : Control { foreach (varcontrol in controlCollection) { if (control is T)…
-
16
votes4
answers9242
viewsA: Datetime field error message
The problem is because an ASP.NET MVC project comes configured with the culture en-US by default. This validation message is done by jQuery using Unobtrusive Ajax and Validation, that need to be…
-
4
votes2
answers731
viewsA: Change Context according to application
Just have more options in your context constructor: public Contexto() : base("BancoDados") { Database.SetInitializer<Contexto>(null); } public Contexto(String nomeDaConnectionString) :…
-
1
votes1
answer546
viewsA: Random results in SQL queries without repeating (Scroll Infinity)
The select below handle of lines 1 to 20. Then just switch to the offset values of your paging to work: SELECT * FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY uma_coluna_qualquer ) AS linha, * FROM…
-
1
votes3
answers1352
viewsA: How to transform a date into a string format without signals in Datetime?
DateTime dateTime = new DateTime(Convert.ToInt32(data.Substring(4, 4), Convert.ToInt32(data.Substring(2, 2), Convert.ToInt32(data.Substring(0, 2), Convert.ToInt32(hora.Substring(0,…
-
4
votes2
answers490
viewsA: How to persist the status of a queue of requests?
Approach 1: Priority An approach to solve this would be to put a column Prioridade, which is a enumerable. For example: public enum Prioridade { Minima, Baixa, Media, Alta, Maxima } The standard…
-
2
votes1
answer4362
viewsA: Query to the C# mvc database
Warning: this answer was developed from what the author of the question mentioned. Any redundancy or odd detail that may appear is from the various editions that this response had. I’m guessing you…
-
3
votes1
answer167
viewsA: Doubt with relational modeling
According to the comments and aspects presented in the question, the best way to model its tables is the following: Immovable: id, nome, cidade_id, rua, numero, complemento, cep, bairro, ... Cities:…
-
3
votes2
answers300
viewsA: What can I use to replace the Hidden input in ASP NET MVC?
There is no reason to feel this lack of security. It should only be exposed in View data that can be manipulated by it. In the case of Webforms, what happens is that this information is written on…
-
0
votes2
answers1041
viewsA: Failed to convert nvarchar'VINET' value to int data type
The error occurs because your grdTeste is waiting for a column called VINET, represented by a whole, but that the column of the bank is represented by a nvarchar or some similar type of data. Change…
-
2
votes1
answer275
viewsA: How to add new properties to a user using Identity?
How can I create new properties using the Useridentity that comes by default when creating an MVC 5 application? Extending the class IdentityUser. For example: public class ApplicationUser :…
-
7
votes1
answer4795
viewsA: Apache Maven scopes usage situations
Compile The package is considered in the build. If there is packaging, the dependency is included in the package. Provided The package is considered in the compilation, but is not included in the…
-
1
votes2
answers1071
viewsA: How to know the name of the Actionresult that called the view?
This is because you used an element of ViewBag to call the HtmlHelper. This solves: @using (Html.BeginForm(ViewBag.ActionResult.ToString(), "MeuController", FormMethod.Post, new { @class =…
-
3
votes2
answers149
viewsA: Include Entityframework
That is to say: public class Pessoa { [Key] public int PessoaId { get; set; } public int EnderecoId { get; set; } public virtual Endereco Endereco {get; set;} } public class Endereco { [Key] public…