ASP.NET Partial View rendering on all pages
I have a search page with different tabs to search different collections of items. I made partial views for each of the different collections, however, one of the partial views is rendering on all the other views, while the other only render on their respective pages. I'm not sure what is causing this.
The index file looks like this:
My file layout looks like this:
[
EDIT: Fixed it, I noticed that the other tabs had a section class="site-content" id="skip-to-content"
and the partial that was throwing problems did not. Added the and it was fixed.
See also questions close to this topic
-
Cascading databound <ajaxtoolkit:combobox> and <asp:dropdownlist> in asp.net
I have an
asp.net
search form that includes anajaxToolkit Combobox
and a standardasp DropDownList
. Both controls are bound to two separatedSqlDatasource
components.Something like this:
<ajaxToolkit:ComboBox ID="cbConvenzionato" runat="server" AutoCompleteMode="SuggestAppend" DropDownStyle="DropDownList" DataSourceID="sdsConvenzionati" DataTextField="nome" DataValueField="id" AutoPostBack="true" OnSelectedIndexChanged="cbConvenzionato_SelectedIndexChanged" /> <asp:DropDownList ID="ddlVeicoli" DataSourceID="sdsVeicoli" DataTextField="targa" DataValueField="id" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlVeicoli_SelectedIndexChanged" AppendDataBoundItems="true"> <asp:ListItem Text="TUTTI" Value="" Selected="True" /> </asp:DropDownList> <asp:SqlDataSource ID="sdsConvenzionati" runat="server" ConnectionString="<%$ ConnectionStrings:db %>" ProviderName="<%$ ConnectionStrings:db.ProviderName %>" SelectCommand=" SELECT id, nome FROM anag_convenzionati ORDER BY nome;" /> <asp:SqlDataSource ID="sdsVeicoli" runat="server" EnableCaching="false" CancelSelectOnNullParameter="false" ConnectionString="<%$ ConnectionStrings:db %>" ProviderName="<%$ ConnectionStrings:db.ProviderName %>" SelectCommand=" SELECT id, targa FROM veicoli_contratti WHERE ((@id_convenzionato IS NULL) OR (id_convenzionato = @id_convenzionato)) ORDER BY targa;"> <SelectParameters> <asp:ControlParameter Name="id_convenzionato" ControlID="cbConvenzionato" PropertyName="SelectedValue" Direction="Input" ConvertEmptyStringToNull="true" DbType="Int32" DefaultValue="" /> </SelectParameters> </asp:SqlDataSource>
There's also a third
sqldatasource
(sdsNoleggi
) that feeds agridview
but this's not a problem right now.In code behind I have two event handlers:
protected void cbConvenzionato_SelectedIndexChanged(object sender, EventArgs e) { sdsVeicoli.Select(DataSourceSelectArguments.Empty); Search(); } protected void ddlVeicoli_SelectedIndexChanged(object sender, EventArgs e) { Search(); } private void Search() { sdsNoleggi.Select(DataSourceSelectArguments.Empty); }
I tought in this way I should filter
ddlVeicoli
items after selecting an item incbConvenzionato
... but it's not working... why?If I look into
sdsVeicoli
SelectParameters
in debug I can seeid_convenzionato
being correctly set to selected value (id coming fromcbConvenzionato
) I bet also thatsdsNoleggi
dataset wiil be correctly updated with new values since I did this many times before. So why bound control it's not? I tried also to force addlVeicoli.DataBind()
aftersdsVeicoli.Select()
call ... but this had no effect. -
Swagger UI not working for REST API (asp.net web api2) application
I have asp.net mvc project with .NET Framework 4.7.2 and the same project contains asp.net web api2 controller in a separate folder : Controllers. The solution is legacy. The API are already in use in the PRODUCTION environment. Now I added the Swagger nuget package (Install-Package Swashbuckle -Version 5.6.0) to this existing project. Post that I see a SwaggerConfig.cs added to the App_Start folder of the Solution Explorer.
Here the asp.net mvc controllers are used by App1 pointing to the server: www.app1.com and asp.net web api2 controllers are used by another frontend angular app: App2 pointing to the server : www.app2.com
The complete deployment package for both App1 and App2 are hosted in IIS
Any request related to App1 is handled by www.app1.com and any api request related to App2 (Angular frontend) is handled by App1 only using IIS Rewrite rules at App2 level which redirect any api request to App1 only.
Now in this case when I tried to navigate to www.app1.com/swagger , I see it is loading the SwaggerUI for me, but when I tried to navigate to www.app2.com/swagger it is not working and instead of that it is loading the Angular frontend application
Here goes the App1 and App2 at IIS level:
Can anyone help me here by providing their guidance to fix this issue?
-
Cors error missing allow origin header. MailKit
I have
cors error missing allow origin header
error only on ONE post request. My CORS Policypublic void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder.SetIsOriginAllowed(_ => true) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); }
Every request work fine, but one POST request fails, it's really weird. Code in controller action which failed use MailKit and SMTP to send email, maybe that's cause
-
GroupJoin without having to select contents from joined list
So I've got two classes that I'm trying to combine into a ViewModel for use in the application. I'm trying to find the lambda syntax to perform a left join between the two objects (Actual Delivery, DeliveryHdr). For some context the DeliveryHdr is a scheduled delivery on a schedule and the Actual Delivery is details collected once the delivery is made. I'm using the provided method (CovertToViewModel) to conmbine the two objects and return a list of ViewModels and it functions like I want it to but I'm thinking there has to be an easier way? How can I perform a 1 to 1 left join without having to perform Select's on the joined List like I've done below?
public partial class ActualDelivery { public int ActualDeliveryId { get; set; } public int DeliveryId { get; set; } public string DockDoor { get; set; } public string ArrivalComments { get; set; } public string SetTemp { get; set; } public string Unloader { get; set; } public DateTime? UnloadStart { get; set; } public DateTime? UnloadEnd { get; set; } public int? ActualAmbientFull { get; set; } public int? ActualAmbientMixed { get; set; } public int? ActualReefer { get; set; } public int? ActualCageVault { get; set; } public int? ActualBlc { get; set; } public int? ActualTotalPallets { get; set; } public int? ActualTotalLpns { get; set; } public DateTime? CreatedDttm { get; set; } public string CreatedUser { get; set; } public DateTime? UpdatedDttm { get; set; } public string UpdatedUser { get; set; } }
public partial class DeliveryHdr { public int DeliveryId { get; set; } public DateTime? LoadDate { get; set; } public DateTime? ScheduledTime { get; set; } public DateTime? ArrivalTime { get; set; } public int? LoadNumber { get; set; } public string Shift { get; set; } public string SupplierNumber { get; set; } public string SupplierName { get; set; } public string Carrier { get; set; } public bool? IsCancelled { get; set; } public bool? IsConfirmed { get; set; } public bool? IsBackHaul { get; set; } public int? ActAmbientFullPallets { get; set; } public int? ActAmbientMixedPallets { get; set; } public int? ActReeferPallets { get; set; } public int? ActCageVaultPallets { get; set; } public int? ActBlcpallets { get; set; } public int? ActTotalPallets { get; set; } public int? ActTotalLpns { get; set; } public bool? MarkAsDeleted { get; set; } public string CreatedUser { get; set; } public DateTime? CreatedDttm { get; set; } public string UpdatedUser { get; set; } public DateTime? UpdatedDttm { get; set; } }
public class ActualDeliveriesViewModel { public int DeliveryId { get; set; } public int ActualDeliveryId { get; set; } public string CompositeId { get; set; } public DateTime? LoadDate { get; set; } public DateTime? ScheduledTime { get; set; } public DateTime? ActualTime { get; set; } public string Shift { get; set; } public int? LoadNumber { get; set; } public string SupplierName { get; set; } public string Carrier { get; set; } public bool? IsConfirmed { get; set; } public bool? IsBackHaul { get; set; } public bool? IsCancelled { get; set; } public string DockDoor { get; set; } public string ArrivalComments { get; set; } public string SetTemp { get; set; } public string Unloader { get; set; } public DateTime? UnloadStart { get; set; } public DateTime? UnloadEnd { get; set; } public int? ActualAmbientFull { get; set; } public int? ActualAmbientMixed { get; set; } public int? ActualReefer { get; set; } public int? ActualCageVault { get; set; } public int? ActualBlc { get; set; } public int? ActualTotalPallets { get; set; } public int? ActualTotalLpns { get; set; } }
public List<ActualDeliveriesViewModel> CovertToViewModel(List<DeliveryHdr> deliveries, List<ActualDelivery> actuals) { return deliveries.Where(e => e.MarkAsDeleted == false).GroupJoin(actuals, d => d.DeliveryId, a => a.DeliveryId, (d, a) => new ActualDeliveriesViewModel() { DeliveryId = d.DeliveryId, ActualDeliveryId = a.Select(i => i.ActualDeliveryId).FirstOrDefault(), CompositeId = d.DeliveryId + "_" + a.Select(i => i.ActualDeliveryId).FirstOrDefault(), LoadDate = d.LoadDate, ScheduledTime = d.ScheduledTime, ActualTime = d.ArrivalTime, LoadNumber = d.LoadNumber, SupplierName = d.SupplierName, Carrier = d.Carrier, IsConfirmed = d.IsConfirmed, IsBackHaul = d.IsBackHaul, IsCancelled = d.IsCancelled, DockDoor = a.Select(i => i.DockDoor).FirstOrDefault(), ArrivalComments = a.Select(i => i.ArrivalComments).FirstOrDefault(), SetTemp = a.Select(i => i.SetTemp).FirstOrDefault(), Unloader = a.Select(i => i.Unloader).FirstOrDefault(), UnloadStart = a.Select(i => i.UnloadStart).FirstOrDefault(), UnloadEnd = a.Select(i => i.UnloadEnd).FirstOrDefault(), ActualAmbientFull = a.Select(i => i.ActualAmbientFull).FirstOrDefault(), ActualAmbientMixed = a.Select(i => i.ActualAmbientMixed).FirstOrDefault(), ActualBlc = a.Select(i => i.ActualBlc).FirstOrDefault(), ActualCageVault = a.Select(i => i.ActualCageVault).FirstOrDefault(), ActualReefer = a.Select(i => i.ActualReefer).FirstOrDefault(), ActualTotalPallets = (a.Select(i => i.ActualAmbientFull).FirstOrDefault() + a.Select(i => i.ActualAmbientMixed).FirstOrDefault() + a.Select(i => i.ActualBlc).FirstOrDefault() + a.Select(i => i.ActualCageVault).FirstOrDefault() + a.Select(i => i.ActualReefer).FirstOrDefault()) ?? 0 }).ToList(); }
-
OutputCache an ActionResult that only returns a View
Would it make sense to [OutputCache] something like this?
[HttpGet] public ActionResult About() { return this.View("About"); }
-
The entity type was not found. Ensure that the entity type has been added to the model
I'm new to ASP.NET Core and i'm trying to insert an entity into an Entity Framework Core model scaffolded from a simple existing MariaDB database.
This is the entity model:
public class ScrapeAsincroni { public int Id { get; set; } public string Paese { get; set; } public string Engine { get; set; } public string Keywords { get; set; } }
This is the controller action that is supposed to add the entity:
public JsonResult create(string paese, string engine, string keywords) { ScrapeAsincroni scrapeAsincrono = new ScrapeAsincroni { Paese = paese, Engine = engine, Keywords = keywords }; _context.Add(scrapeAsincrono); try { _context.SaveChangesAsync(); } catch (Exception ex) { return Json(new Dictionary<string, int?> { { "id", null } }); } return Json(new Dictionary<string, int?>{ {"id", scrapeAsincrono.Id} }); }
The database context (_context) has been initialized on the controller's constructor. the line
_context.Add(scrapeAsincrono);
throws the following exception:
System.InvalidOperationException: The entity type 'ScrapeAsincroni' was not found. Ensure that the entity type has been added to the model.
This is the modelBuilder code relative to this model
public partial class ScraperDbContext : DbContext { public ScraperDbContext() { } public ScraperDbContext(DbContextOptions<ScraperDbContext> options) : base(options) { } public virtual DbSet<ScrapeAsincroni> ScrapeAsincroni { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings. optionsBuilder.UseMySql("server=51.255.74.100;port=3306;user=luca.ceccagnoli;password=Hb93#2ql;database=scraper_db", x => x.ServerVersion("10.3.25-mariadb")); } } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<ScrapeAsincroni>(entity => { entity.HasComment("Informazioni su una ricerca asincrona dello Scraper"); entity.Property(e => e.Id) .HasColumnName("id") .HasColumnType("int(11)"); entity.Property(e => e.Engine) .HasColumnName("engine") .HasColumnType("varchar(255)") .HasCharSet("utf8") .HasCollation("utf8_general_ci"); entity.Property(e => e.Keywords) .IsRequired() .HasColumnName("keywords") .HasColumnType("text") .HasCharSet("utf8") .HasCollation("utf8_general_ci"); entity.Property(e => e.Paese) .HasColumnName("paese") .HasColumnType("varchar(255)") .HasCharSet("utf8") .HasCollation("utf8_general_ci"); }); OnModelCreatingPartial(modelBuilder); } partial void OnModelCreatingPartial(ModelBuilder modelBuilder); }
I can't seem to understand why this happens, and couldn't find any solutions online.