Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
1
votes3
answers179
viewsA: Select the Controller name via Javascript
I usually use the following: @ViewContext.RouteData.Values["controller"].ToString() @ViewContext.RouteData.Values["action"].ToString() See more about ViewContext here. Additionally, you can…
-
1
votes1
answer971
viewsA: Manipulation of TXT files in C#
You can convert the text file to a DataSet and save the DataSet back to text. Here’s how to use the following Helper: public class TextToDataSet { public TextToDataSet() { } /// <summary> ///…
c#answered Leonel Sanches da Silva 88,623 -
5
votes2
answers353
viewsA: What is the difference between @Url.Content("~/css/bootstrap.css") and only "/css/bootstrap.css"
This: <link href="css/bootstrap.css" rel="stylesheet"> It’s not like this, as much as it seems: <link href="@Url.Content("~/css/bootstrap.css")" rel="stylesheet"> In the first mode, the…
-
2
votes2
answers174
viewsA: Use of LINQ to query a collection
It would not be easier to make a direct consultation of the bank? No, because LINQ is not only for formulating SQL queries. It is a much more powerful resource. LINQ, according to Wikipedia article,…
-
2
votes2
answers1209
viewsA: Doubts about how to consume Ws Nfs-e Curitiba
The Municipality of Curitiba was once my client. Normally, the Web Services of them are made in C#, whose documentation can be easily accessible through the address:…
-
1
votes3
answers292
viewsA: Entity Framework 4 - Migrations error: The ... type is not defined in the <namespace> namespace. Map (Alias=Self)
The mapping class is in another namespace other than the namespace of Models. When setting a new map, make sure you’re using the required dependencies. using SisprodIT2.Models;…
-
3
votes2
answers206
viewsA: Where to place the View Model rule
Seems like a good approach in the builder. Additionally, I would make the class constructor without parameters private, to avoid another form of class initialization other than this: public class…
-
8
votes1
answer377
viewsA: To automatically fill fields when saving object in database
Note that the code to save the user is here: if (entry.Property("UsuarioModificacao") != null) { entry.Property("UsuarioModificacao").CurrentValue = HttpContext.Current != null ?…
-
3
votes2
answers490
viewsA: How to save data to SQL database - Submit
Missing set a primary key in your Model, and a few more things. Change to the following: public class Combustivel { [Key] public int CombustivelId { get; set; } [Required] public decimal km_inicial…
-
4
votes1
answer174
viewsA: Loading Renderaction within _Layout
Use @Html.Action. Attention! Beware when working with @Html.Action. Codes can enter into loop or stop the entire application if it is misspelled. Some tips: 1: Controller common public abstract…
-
3
votes1
answer666
viewsA: org.xml.sax.Saxparseexception; lineNumber: 10; columnNumber: 24; Attribute "Singleton" must be declared for element type "bean"
Xfire does not work in Spring 3.2 and above. Use of the package is required for use of the following bean (web-application-config.xml): <bean…
-
2
votes1
answer666
viewsQ: org.xml.sax.Saxparseexception; lineNumber: 10; columnNumber: 24; Attribute "Singleton" must be declared for element type "bean"
I am upgrading a (old) project to the latest libraries, such as Spring (from version 3.2.4.FINAL to version 4.3.11.FINAL). One of the errors that appears in Tomcat 6 is:…
-
1
votes1
answer685
viewsA: Display balloon popup on a label
What you want is a Tooltip. There are several libraries that do this. Possibly you want some that behave like this one. Tooltips are in JS, so they are independent of ASP.NET MVC. Use is done as…
-
3
votes1
answer642
viewsA: Confirmation of data Registrations E-mail Password
ASP.NET MVC has it ready in Model, automatically replicable to Views. Example: Viewmodel public class RegisterBindingModel { [Required] [EmailAddress] [Display(Name = "Email")] public string Email {…
-
0
votes3
answers1898
viewsA: How to call a Javascript Function inside a Razor?
The best event to check the date is the field output, made by the event onblur: @Html.EditorFor(model => model.DataNascimento, new { htmlAttributes = new { @class = "form-control", @onblur =…
-
1
votes1
answer376
viewsA: How much to use @Html.Actionlink or Javascript
Well, this usage is incorrect: <ul class="nav child_menu"> <li><a>@Html.ActionLink("Painel Inicial", "Index_Comercial", "Home")</a></li> </ul> @Html.ActionLink…
-
2
votes2
answers366
viewsA: Integration going into loop
This line: Console.WriteLine("URL do pagamento : " + paymentRedirectUri); It is a test to write in console the return of the URL that should be used to redirect the user to Pagseguro and make their…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
1
votes1
answer224
viewsA: Error updating Record with EF
Your modeling is incorrect. A Customer has one or more Addresses, therefore: [DisplayColumn("Nome")] public class Cliente { [Key] public Int64 ClienteId { get; set; } [Required] public String Nome {…
-
2
votes2
answers137
viewsA: Problems with ASP.NET MVC
UsuarioViewModel is not an enumeration (does not implement IEnumerable), therefore, it cannot be iterated (it cannot be used in a foreach). Your Action Index returns nothing. Hardly this code will…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
8
votes3
answers1653
viewsA: Picking up part of the phone
Using regular expressions, we can do so: using System.Text.RegularExpressions; var teste = Regex.Match("(12) 3456-7890", @"\((\d{2})\)\s?(\d{4,5}\-?\d{4})"); // teste.Groups[0] imprime o número. //…
-
9
votes4
answers4174
viewsA: What is the meaning of the operator ( * ) asterisk?
Splat I mentioned this in another question about PHP. It is an operator that assumes that you will pass to the method or assignment a list of parameters. For example: def funcao1(a, b=None, c=None):…
-
6
votes2
answers1515
viewsA: Data Displayfor display formatting
Html.DisplayFor() does not serve for date and time separation as you want. The method meets well only for the integral use of variable information. Use, instead of this:…
-
2
votes1
answer80
viewsA: Use Separate Date Time
If you necessarily want to use a database field, you will need a Viewmodel to consolidate date and time. SeuModel.cs public DateTime DataHora { get; set; } SeuViewModel.cs [DataType(DataType.Date)]…
-
3
votes2
answers371
viewsA: Working with Seed + FK Method
First save the states: protected override void Seed(Projeto.Models.Context context) { IList<Estado> estados = new List<Estado>(); estados.Add(new Estado() { Nome = "Acre", Sigla = "AC"…
-
4
votes3
answers7584
viewsA: Calling the Controller Method
I’m doing a project for the College, and I’m having a hard time understanding how to create a button and call an Actionresult in the Controller... If we’re talking about a <input> of the kind…
-
3
votes2
answers1172
viewsA: How to make a button with Razor and Css
Do not use or <input>, nor @Html.ActionLink. Use: <div> <a href="@Url.Action("Clientes", "Comercial")"> <div class="but_clientes">Clientes</div> </a> </div>…
-
1
votes1
answer222
viewsA: Error calling a method in ASP.NET Web API and Ninject
As spoken by comment, check if the package Webactivatorex was installed together with Ninject. The mistake: Cannot be null Parameter name: root It’s triggered by the Ninject, not exactly by the…
-
0
votes1
answer209
viewsA: Passing as parameter a generic type in an attribute in . NET MVC
You can pass a type to your attribute: [Authorized(typeof(User))] Your attribute would have to change a little: public class Authorized : ActionFilterAttribute { private Type guardType; ... } The…
-
4
votes1
answer177
viewsA: How can I turn an INI file into a Dict?
Yes, using configparser: import configparser import os configuracao = configparser.ConfigParser() configuracao.read(os.path.join(os.getcwd(), "meuarquivo.ini")) host =…
-
4
votes2
answers62
viewsA: Save Campo Automatico
You need to select the Estado again while saving: [HttpPost] [ValidateAntiForgeryToken] public async Task<ActionResult> Criar(Class1 class1) { if (ModelState.IsValid) { using (var scope = new…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
1
votes1
answer469
viewsA: How to save in 2 tables at the same time
This code doesn’t make much sense. If the items are part of a Locacao, you can save everything just by using the Locacao. Anyway, I’m going to assume that for some reason, you need these items to…
-
0
votes1
answer226
viewsA: MVC - Store user permissions in session using NLB - Network Load Balancing
Whether it is really necessary to use sessions to preserve user permissions, you can use a Stateserver or a Sqlserver. The application configuration is done as follows: Stateserver…
-
2
votes2
answers472
viewsA: MVC and DAO - Data Rules
Not on DAO. On Model. Conceptually speaking, because it is a set rule (a field cannot be repeated between entities), the ideal is to define itself in Model, though not all the frameworks have this…
-
2
votes1
answer648
viewsA: Httpcontext.Current.Session - Null
When updating your system, IIS expires all active sessions. This behavior is correct and predicted. It makes no sense to keep sessions from a outdated system version. The simplest fix is in checking…
-
4
votes1
answer229
viewsA: Redirect with MVC Timer
It’s not much of a secret: <script type="text/javascript"> function countdown(){ var now = new Date(); var eventDate = new Date(2016, 10, 01); if (now > eventDate)…
-
5
votes1
answer90
viewsA: How to list products from a single restaurant?
I would do so: public ActionResult Cardapio(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var restaurante = db.Restaurantes .Include(r => r.Produtos)…
-
2
votes1
answer154
viewsA: Does not send email password recovery by Sendgrid
This version of your code does not work with credentials. Instead of passing user and password (as in the old method), directly pass the Key API. Also try to implement this other example, more…
-
2
votes1
answer156
viewsA: jQuery calling an action
My question is whether I should call Action via jquery to validate the model and within the Action make a Rest call (which was built in web api) and return the response in the javascript function.…
-
0
votes1
answer60
viewsA: List reservations by Administrator
This brings all the reservations, obviously: return View(db.Reservas.ToList()); This modeling doesn’t make any sense. A reservation can only belong to a restaurant: public class Reserva { [Key]…
-
1
votes1
answer34
viewsA: Make element disappear according to system date
Using Moment js., and jQuery, this is very simple. $("a.web-thumb").each(function() { var data_atual = moment(); var data_teste = moment("13/09/2016", "dd/MM/yyyy"); // Aqui eu coloquei fixo, mas…
jqueryanswered Leonel Sanches da Silva 88,623 -
10
votes2
answers88
viewsA: Sql Server 2014 Null Value
This is one of the most particular subtleties of working with databases. This: if (@var = null) -- Preste atenção aqui set @bool = 1 else set @bool = 0 It’s different from this: if (@var is null) --…
-
1
votes1
answer82
viewsA: View Field when Selecting Dropdownlist and save
The correct thing is to separate the names of the suggested load fields and another workload. Something like this: <div class="form-group"> @Html.LabelFor(model => model.CargaHoraria,…
-
0
votes2
answers608
viewsA: @font-face c# MVC Bootstrap
Since the resolution of references is done by route, and not by static directory, you need to configure the application to allow static paths by file type. This is done by putting the following in…
-
6
votes2
answers513
viewsA: Reflection C#, how does it work?
Before I start answering you, it’s important to explain what this code you put in the question is for. I set up a Fiddle to explain how it converts an object to XML. We declare a class: public class…
-
5
votes1
answer38
viewsA: Lack of Assembly Reference C#
You are confusing the event. The correct is KeyEventArgs. Not MouseEventArgs. Your code makes no sense. If the goal is to test which button mouse was pressed, change the event to: private void…
-
3
votes1
answer372
viewsA: Location.href is not transferring me from ASP.NET MVC page
Basically, there’s a lot of things wrong here. _ViewStart is not a View represented by a route. Therefore, it cannot be called by JS. A login authentication route never should be GET. GET is a…
-
1
votes2
answers800
viewsA: Bundle doesn’t work when I publish the site
This problem is a bit complex and bizarre because the solution is not obvious. The problem lies in the reference to your CSS. Here: bundles.Add(new StyleBundle("~/Content/css/font-awesome").Include(…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
7
votes2
answers277
viewsA: Value of Enum C#
I have read in some questions this is nonsense. What is wrong in these code snippets? Nothing. I don’t know what is so absurd in the answers you’ve been reading. The only thing this decoration does…
-
4
votes1
answer700
viewsA: Change table column names created by Asp.Net Identity
You can change the name of the columns in the Aspnetusers table that Identity creates in the database? No. Column names are essential for a security check by IdentityDbContext at the initialization…
-
1
votes1
answer60
viewsA: Is it possible to integrate SELENIUM IDE testing into Github?
Apparently, no. Selenium Webdriver can be integrated into the Github API. The difference between the Selenium IDE and the Selenium Webdriver is that you will have to program the code in some…