Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
5
votes1
answer2820
viewsA: Render pages within _Layout.cshtml of other types. Asp.Net MVC 4
Modify: [HttpPost] public ActionResult RequestToAccept() { ProfessionalUser pUser = Session["ProfessionalUserLogged"] as ProfessionalUser; return View(pUser.RequestsToAccept); } To:…
-
2
votes2
answers197
viewsA: Error making an insert in the database
The mistake means that AlunoId is not defined. As stated in other answers, your View needs to have one of two things: @Html.HiddenFor(model => model.AlunoId) Or else @Html.DropDownListFor(model…
-
1
votes1
answer138
viewsA: How do I send html from one view to another view?
In fact from what I understand, you want to generate the graph and the information all within a PDF. I’ve never done this, but there is a Nuget package that accesses a website and converts it to…
-
2
votes2
answers363
viewsA: EF Relationship between 3 Tables
I don’t know Fluent API syntax where it is possible to define an association between 3 entities. I think it looks better if you map the model and set the keys on it: public class FluxoPassoAcao {…
entity-frameworkanswered Leonel Sanches da Silva 88,623 -
2
votes3
answers1328
viewsA: Returns Json of object in C# with Entity Framework
If the question is just to take the dependency from the Entity Framework, simply enumerate the result. IList<AgendaHorario> agendaHorario = db.AgendaHorario.Where(w => w.AgendaHorarioID ==…
-
1
votes1
answer1055
viewsA: Send a modelView as parameter to a modal bootstrap
I don’t know exactly what that line does: var data = '@COOPA.Core.Common.JsonUtil.ToJson(Model)'; But data need to have the following to work: { 'm_Nome': 'Um nome qualquer', 'm_Cota': 'Cota',…
-
10
votes2
answers2568
viewsA: OWIN and Katana - How does it really work and how to use it?
The main goal of OWIN is to be able to develop applications and components that are easier to write and consume than in the traditional ASP.NET way, in addition to eliminating the dependency on…
-
2
votes1
answer275
viewsA: Change banner every page refresh
I’m guessing your banner is on a banner list, something like List<Banner>: banners.ElementAt(new Random().Next(0, banners.Count));…
-
2
votes3
answers1054
viewsA: Regex to select specific stretch
(locador[a]?):(.*)\n I don’t know what technology you’re using, but basically you’d have to take the name of the second group (second set in parentheses) and delete the \n of the end.…
-
6
votes1
answer4965
viewsA: Transactionscope does not transact
Several steps to enable distributed transaction support: Administrative Tools > Services Enable the Coordinator of Distributed Transactions if it is disabled; Return to Administrative Tools >…
-
0
votes1
answer85
viewsA: Sendmessagetowincontrol error - A control type was not specified
The attribute onload inside <body> is using being increasingly discouraged. The updated use would look something like this: <head runat="server"> <title>Impressão de…
-
5
votes1
answer913
viewsA: Correct Statement Classes Model MVC Ninject
Not that the approach is wrong, but she’s expensive, computationally speaking. Not having the properties of foreign keys in the relations from 1 to N makes the application have to necessarily load…
-
30
votes2
answers9287
viewsA: Example of ASP.NET Identity using SQL Server
This answer is the basics of having an ASP.NET MVC5 application using ASP.NET Identity with Individual User Accounts, as requested by the question. Therefore, I do not intend to add to the answer by…
-
6
votes1
answer3291
viewsA: How to pass parameter from one Controller to another in Asp.Net
Otherwise: return RedirectToAction("OutraAction", "Controller", new { minhaClasse = /* objeto do tipo MinhaClasse */, area = "area"}) There yours Controller gets like this: public ActionResult…
-
2
votes1
answer563
viewsA: How to pick up Radiobuttonfor value through Formcollection and save to SQL Server BD
The conversion of Boolean for bit is transparent. I don’t know how your process is, but if the parameter @sex is a bit, this statement: cmd.Parameters.AddWithValue("@sex", pSimpleUser.Sex); Works…
-
9
votes2
answers5287
viewsA: How to implement the Repository Standard in C# with EF?
Using repository on top of Entity Framework is always a bad practice. In this answer, I only solve the generic code problem that the questioner is having, but this does not validate the use of the…
-
7
votes6
answers8712
viewsA: How and when to use Finally after a Try?
The finally only serves for use together with a try/catch. Its use is indicated for a block situation try where, if successful or failed, the code will always be executed. This is useful for object…
-
2
votes1
answer873
viewsA: Change font size using @Html.Label
@Html.Label("MeuLabel", new { @style = "color: #000000" }) Just fill in the @style with the CSS style you want.
-
4
votes3
answers1183
viewsA: How to Dropdown ASP NET MVC
@{ var lstOpcoes = Enum.GetValues(typeof(SituacaoEnum)).OfType<SituacaoEnum>().Select(sa => new SelectListItem { Text = sa.ToString(), Value =…
-
1
votes2
answers7317
viewsA: How to create user with encryption password?
The method below encodes the user’s password in the standard Base 64, but can be used MD5 without problems, only replacing the Base 64 method with an equivalent MD5: /// <summary> /// Encode…
-
1
votes1
answer68
viewsA: Entityframework 6 - Load Model and its dependencies in Home
Very simple. Modify your code to the following: <div class="container"> @if (this.Model != null && this.Model.Count() > 0) { foreach (var item in this.Model) { <div…
-
4
votes2
answers2534
viewsA: Rendering Partials in ASP.NET MVC
Following MVC good practices, if your project is minimal, you have to be able to enter an occurrence even if you don’t have the Students screen ready. To enter the occurrence, modify your Controller…
-
3
votes1
answer188
viewsA: Partial does not render
You forgot to pass the Model inside Partial. See the line @Html.Partial down below: <div id="ocorrencias" class="panel-collapse collapse in"> <div class="panel-body"> @foreach (var…
-
2
votes2
answers1040
viewsA: Null check returns reference error
James, I would exchange this code: if (Model.ID > 0) // Se for uma referência vazia, o valor será 0 { <input type="hidden" name="idTransacao" value="@Model.ID" /> } For this:…
-
3
votes1
answer436
viewsA: Doubt in View and Controller construction with cardinality dependent entity N
In entities with cardinality N, the correct is to use a Nuget package called BeginCollectionItem: http://www.nuget.org/packages/BeginCollectionItem/ The original doubt began here: Map Id of one…
-
3
votes1
answer231
viewsA: Map Id of one model to another without a Dropdownlist
Just change: @Html.DropDownList("AlunoId", String.Empty) For: @Html.HiddenFor(model => model.AlunoId) <div>@model.Aluno.Nome</div> Controller public ActionResult…
-
5
votes3
answers1018
viewsQ: Serialize XML for REST API with Correct Accent
I am creating a small read-only REST API service on a client system. It uses Spring MVC to fulfill the requests and the purpose of each request is to return a JSON with certain information to…
-
54
votes2
answers6578
viewsA: Business Rules in the Database - what are the advantages and disadvantages?
I will try to focus this answer on relational databases, which I have the most experience and which should better cover the scope of the question. Perks Data security and consistency are greater;…
-
2
votes2
answers2389
viewsA: Stored Procedure with output parameter being the Id of the last insertion. C#
Open another command and use the following: SELECT IDENT_CURRENT ('ProfessionalUser') AS UltimoIdInserido; There are other alternatives, such as @@IDENTITY and SCOPE_IDENTITY, but they are relative…
-
2
votes1
answer120
viewsA: url in MVC project of an . html
If static, use in your file _Layout.cshtml: @Html.Partial("_Menu") Create a file for this case _Menu.cshtml If dynamic, use a Action: @Html.Action("Menu") Create for this case a Controller common…
-
3
votes1
answer138
viewsA: Preview the data before saving to the database
Here’s what I’d do: One Action calling for Preview with the following signature: public ActionResult Preview(Noticia noticia) { ... } To View would have all the attributes Hidden:…
-
2
votes4
answers1297
viewsA: Download excel file
The most correct is to specify a Action in the Controller return a FileResult. For example: public FileResult ExportarExcel() { // Monte aqui o arquivo Excel. // conteudoDoArquivo deve ser um byte[]…
-
3
votes1
answer1367
viewsA: Get list of checkboxes in the controller in Asp.Net
This way is more complicated because everything has to be done manually. The best way is by using the excellent HtmlHelper, that has Razor methods to assemble the sequence of fields. In the example…
-
3
votes1
answer1765
viewsA: How to render Action by accessing controller in this case?
What you’re trying to get falls more into the concept of Actions with PartialViews. Therefore, some small changes to your code are required. Main Html <section class="section"…
-
4
votes2
answers129
viewsA: Get user-created methods
Use: var m = Objeto.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(x => !x.IsSpecialName).ToArray();
-
1
votes2
answers673
viewsA: Checkboxlistfor with error
According to the documentation: You need to add the following reference to your view first: @using MvcCheckBoxList.Model…
-
1
votes1
answer247
viewsA: Large volume data loading with Nhibernate + Windows Forms
What is the best way to upload ALL this data? How to popular Datagridview when creating a form without a Delay occurring on its opening? Paginando a Datagridview. This answer of the SO gringo has an…
-
0
votes1
answer846
viewsA: "Invalid App Id" error on "Like" Facebook button
The App Id. Look at this line here: js.src = "//connect.facebook.net/pt_BR/all.js#xfbml=1"; She has to be like this: js.src =…
-
3
votes2
answers439
viewsA: How to allow read-only for a certain type of user?
I would do something like that (ASP.NET MVC in Razor + jQuery): @section scripts { @if (User.IsInRole("Diretores")) { <script> $(document).ready(function() { $("input, select,…
-
0
votes1
answer469
viewsA: Problem with Custom Routes and Httphandler in ASP.NET MVC
I asked the same question in the gringo OS and was told by comment that the approach should be changed. No need HttpHandlers, modify routes or anything like that. Simply doing the Controller return…
-
8
votes2
answers6973
viewsA: Many Relationship for Many Entity Framework 6
The Entity Framework is lost when defining the association N to N, even if in theory the declaration of its Model be correct. There are two ways to solve: 1. Using Fluent Configuration in Model…
-
1
votes2
answers282
viewsA: Relate Check Boxes to Radio Buttons
I would do so: An Occurrences Model for the Pupil (name suggestion: Hallucination) of cardinality N, i.e., his model of Pupil would look like this: public class Aluno { /* Aqui vão todas as…
-
3
votes3
answers614
viewsA: Database query in Postgresql
This is because the resolution of the GROUP BY in the Mysql is not orthogonal. All columns that are included in the selection where there is an aggregation operation should be indicated for the…
-
2
votes1
answer593
viewsA: How to use LEAD and LAG using a condition
I assume your table looks like this (in this order): cid_nomec | cid_nucep (nome) 87365000 (nome) 68912350 (nome) 48320000 (nome) 74423970 Somewhere there’s this zip code 77777777: cid_nomec |…
-
2
votes1
answer104
viewsA: Disfigured ASP.NET routes
The Controller is not /LoginProfissional/Logon. IS /Home/Logon. Create a LoginProfissionalController or use the route /Home/Logon.…
-
25
votes4
answers4635
viewsA: To what extent is it not advisable to use an ORM?
About the Entity Framework The implementation of DbSet<> makes the data context load the database record only once during the life cycle of the Controller. Therefore, the performance…
-
6
votes3
answers19465
viewsA: Convert string to MYSQL integer
Use CAST(): SELECT mov . * , prod.produto, prod.unidade, prod.icms, prod.ipi, cast(prod.codigo as unsigned integer) FROM movimentacao AS mov, produtos AS prod WHERE mov.Codigo = prod.codigo Source:…
-
3
votes1
answer290
viewsA: Questions regarding the use of . dbml files
edmx is the modeling file for the Entity Framework; dbml is the modeling file for LINQ-2-SQL. LINQ-2-SQL is a deprecated standard, so it is well recommended that you switch everything to edmx. To…
-
2
votes1
answer118
viewsA: ASP.net MVC with WIF
The way to record this on Razor is very similar. It would look like this: @{ Register TagPrefix="wif" Namespace="Microsoft.IdentityModel.Web.Controls" Assembly="Microsoft.IdentityModel,…
-
1
votes1
answer101
viewsA: Doubt in Procedure
This is because the individual values are on the first cursor, and the totals on the second. Note that this line: INSERT INTO @SWT_GRF_DESEMPENHO_ANUAL VALUES(@EDEMPRESA_ID, @EMPRESA,…