As your html is used as a widget, you probably need to reload the page hosting the widget. Also it might be cached by the hosting page.
once I change something in razor page and partial views then my application reloads but don't bring the new html
mehmood tekfirst
771
Reputation points
Hi,
I have developed an application in Asp.Net MVC CORE 6.
My user of this application is using it in his html pages like a widget.
Now the problem is once I change something in razor page and partial views then my application reloads but don't bring the new html of .cshtml pages.
see my Program.cs file
using RentalWidget.BLL.DAL;
using RentalWidget.BLL.DB;
using RentalWidget.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using static System.Net.Mime.MediaTypeNames;
var builder = WebApplication.CreateBuilder(args);
string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
builder.Services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
policy =>
{
policy.WithOrigins("https://localhost:7260", "https://localhost:7177",
.AllowAnyHeader()
.WithMethods("POST", "PUT", "DELETE", "GET");
});
});
builder.Logging.AddProvider(new CustomFileLoggerProvider(new CustomFileLoggerConfiguration
{
LogLevel = LogLevel.Information,
LogPath = builder.Environment.ContentRootPath + "/logs/"
//LogPath = builder.Environment.ContentRootPath
//builder.Configuration["FileLogPath:LogPath"]
}));
builder.Services.AddControllersWithViews();
// Add services to the container.
builder.Services.AddHttpClient();
#region Session/Cache Management
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
#endregion
#region Database Configurations
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddSqlServer<CarRentalContext>(connectionString);
builder.Services.AddScoped<ISearchRepository, SearchRepository>();
#endregion
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
#region Session/Cache Middleware
app.UseSession();
#endregion
app.UseCors(MyAllowSpecificOrigins);
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=ParamIndex}/{id?}");
app.Run();
and this is my HomeController for Razor Pages.
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly ISearchRepository _searchRepository;
private readonly IConfiguration Configuration;
public HomeController(IConfiguration configuration, ILogger<HomeController> logger,ISearchRepository searchRepository)
{
_logger = logger;
_searchRepository = searchRepository;
Configuration = configuration;
}
public async Task<IActionResult> ParamIndex(string path = "", string apiKey = "", string homePage = "")
{
ViewBag.SrvDtTime = DateTime.Now.ToString("MM/dd/yyyy HH:mm");
int franchiseId = 0;
int.TryParse(apiKey, out franchiseId);
FranchiseWidgetSettingVM? windgetSetting = null;
windgetSetting = (windgetSetting != null ? windgetSetting : new FranchiseWidgetSettingVM());
ParamPageModel item = new ParamPageModel() { ApiKey = apiKey, Path = path, Data = windgetSetting, HomePagePath = homePage };
return View("~/Views/Home/ParamWidget/ParamIndex.cshtml", item);
}
}
What is the issue with it ?
See the ParamIndex.cshtml file below
@inject IConfiguration Configuration
@using CarRentalWidget.Models.ViewModels
@using CarRentalWidget.Views.Home.ParamWidget
@model ParamPageModel
@{
#region Code
string isLocal = @Configuration["CustomSettings:IsDeploymentLive"];
string liveUrl = @Configuration["CustomSettings:LiveUrl"];
string localUrl = @Configuration["CustomSettings:LocalUrl"];
string baseName = @Configuration["CustomSettings:BaseName"];
string pracitcalLive = @Configuration["CustomSettings:PracitcalLiveUrl"];
string fullUrl = "";
if (!string.IsNullOrWhiteSpace(isLocal) && isLocal.ToLower() == "live")
{
fullUrl = liveUrl + baseName + "/";
}
else
{
fullUrl = localUrl;
}
//FranchiseWidgetSettingVM modelData = (ViewBag.Data != null ? (FranchiseWidgetSettingVM) ViewBag.Data : new FranchiseWidgetSettingVM());
#endregion
}
@*<nav id="breadcrumbid" aria-label="breadcrumb" class="tf-breadcrumb-wrapper" style="display:none;">
</nav>*@
<input type="hidden" id="hdnPath" value="@Model.Path" />
<input type="hidden" id="hdnHomePagePath" value="@Model.HomePagePath" />
@if (Model != null && Model.Data != null)
{
@await Html.PartialAsync("ParamSearchCar.cshtml",Model.Data)
}
@section Scripts{
<script type="text/javascript">
var baseName = '@baseName';
applicationurl = '@fullUrl';
var _app_api_server = "";
var _app_serverimage_path = '@pracitcalLive';
var branchClicked = false;
var isLocal = '@isLocal';
var jQuery;
var $;
/******** Load jQuery if not present *********/
const loadScript = (src, test) => {
return new Promise((resolve, reject) => {
// debugger;
const s = document.createElement('script');
let r = false;
s.type = 'text/javascript';
s.src = src;
s.async = false;
s.onerror = function(err) {
reject(err, s);
};
s.onload = s.onreadystatechange = function() {
// console.log(this.readyState); // uncomment this line to see which ready states are called.
if (!r && (!this.readyState || this.readyState == 'complete')) {
r = true;
//debugger;
resolve();
}
};
const t = document.getElementsByTagName('script')[0];
t.parentElement.insertBefore(s, t);
});
}
function removeJqueryConflict() {
$ = jQuery = window.jQuery.noConflict(true);
}
loadScript('https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js', window.jquery)
.then(() => loadScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js", jQuery.fn.datepicker))
.then(removeJqueryConflict)
.catch((error) => { console.error(error); });
</script>
}
See the ParamSearchCar.cshtml file below
@using CarRentalWidget.Models.ViewModels
@model FranchiseWidgetSettingVM
@{
DateTime curDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
DateTime serverStartDate = new DateTime(curDateTime.Year, curDateTime.Month, curDateTime.AddDays(1).Day, 9, 0, 0);
DateTime serverEndDate = serverStartDate.AddDays(1);
}
<input type="hidden" id="SelectedPickupLoc" value="" />
<input type="hidden" id="SelectedPickupFranchise" value="@Model.FranchiseId" />
<input type="hidden" id="SelectedPickupSuboffices" value="" />
<input type="hidden" id="SrvDtTime" value="@curDateTime.ToString("dd/MM/yyyy")" />
<input type="hidden" id="SrvJustTime" value="@curDateTime.ToString("HH:mm:ss")" />
<input type="hidden" id="ServerStartDate" value="@serverStartDate.ToString("dd/MM/yyyy")" />
<input type="hidden" id="ServerStartTime" value="@serverStartDate.ToString("HH:mm")" />
<input type="hidden" id="ServerEndDate" value="@serverEndDate.ToString("dd/MM/yyyy")" />
<input type="hidden" id="ServerEndTime" value="@serverEndDate.ToString("HH:mm")" />
<input type="hidden" id="TxtBxPickUpLoc" value="@Model.FranchiseName" />
<div class="widget-wrapper">
<div class="widget-slider accordion">
<div class="row step-row">
<div class="col-md-6 swidget-body tf-search-group">
<div class="step-label tf-search-label"> VEHICLE <br />TYPE </div>
<div class="tf-search-field">
<div id="swidget_inner_step_six" class="swidget-inner step-six">
<div class="accordion-item-wrap">
<div class="accordion-header">
<a href="javascript:void(0)" id="vehicle-widget" class="search-opener opener">
<div class="value">
<span id="SelectedCat">Select Vehicle Type</span>
</div>
</a>
</div>
<div class="swidget-field slide tf-search-drop-wrapper">
<div class="swidget-content tf-search-drop">
<div id="view5-widget">
<h2 class="tf-drop-title">SELECT VEHICLE TYPE</h2>
<div class="options">
<div class="vehicles-widget-inner">
<input type="hidden" id="selectCar_Val" name="selectCar_Val" value="" />
<ul class="vehicles-type-list"></ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="swidget-step2">
<button type="button" class="tf-btn tf-btn-lg tf-btn-success" onclick="return searchCar(event);"> Search </button>
</div>
</div>
</div>
</div>
</div>
and this is the browser dev network request.
-
Request URL:
http://localhost:53208/ddd25dade3d04538ab938ab6359b4865/browserLinkSignalR/negotiate?requestUrl=https%3A%2F%2Flocalhost%3A7177%2F&browserName=&userAgent=Mozilla%2F5.0+(Windows+NT+10.0%3B+Win64%3B+x64)+AppleWebKit%2F537.36+(KHTML%2C+like+Gecko)+Chrome%2F108.0.0.0+Safari%2F537.36&browserIdKey=window.browserLink.initializationData.browserId&browserId=76e3-6441&clientProtocol=1.3&_=1673421665957
-
Request Method:
GET
-
Status Code:
200 OK
-
Remote Address:
[::1]:53208
-
Referrer Policy:
strict-origin-when-cross-origin
-
Response HeadersView source
-
Access-Control-Allow-Credentials:
true
-
Access-Control-Allow-Origin:
https://localhost:7177
-
Content-Type:
application/json; charset=UTF-8
-
Date:
Wed, 11 Jan 2023 07:21:05 GMT
-
Server:
Microsoft-HTTPAPI/2.0
-
Transfer-Encoding:
chunked
-
X-Content-Type-Options:
nosniff
-
-
Request HeadersView source
-
Accept:
text/plain, */*; q=0.01
-
Accept-Encoding:
gzip, deflate, br
-
Accept-Language:
en-US,en;q=0.9
-
Cache-Control:
no-cache
-
Connection:
keep-alive
-
Content-Type:
application/x-www-form-urlencoded; charset=UTF-8
-
Cookie:
fpestid=yEdQa6Vly7KEg6amy7Y3C445Fzn3BAJ3vRCfMXwTfEtgmn4YqkmECnpGC2YrsszvBNvt9w
-
Host:
localhost:53208
-
Origin:
https://localhost:7177
-
Pragma:
no-cache
-
sec-ch-ua:
"Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"
-
sec-ch-ua-mobile:
?0
-
sec-ch-ua-platform:
"Windows"
-
Sec-Fetch-Dest:
empty
-
Sec-Fetch-Mode:
cors
-
Sec-Fetch-Site:
cross-site
-
User-Agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
-
Developer technologies | ASP.NET | ASP.NET Core
4,817 questions
1 answer
Sort by: Most helpful
-
Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
2023-01-10T16:15:27.057+00:00