I want to pass a string parameter to an action. Acreated a method in the HomeController
with the following signature:
[HttpGet]
public IActionResult TestView([FromQuery] string test)
{
return View(test);
}
This is my configuration class:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
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();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
When I go to https://localhost:5001/Home/TestView it works ok
When I add a query string ?test=myvalue it fails to find the view. It tries to locate the view using weird paths.
InvalidOperationException: The view 'myvalue' was not found. The following locations were searched:
/Views/Home/myvalue.cshtml
/Views/Shared/myvalue.cshtml
Is that a bug?
question from:
https://stackoverflow.com/questions/65884738/asp-net-core-weird-url-parsing-single-query-string-parameter 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…