英文:
ASP.NET Core React Template with MVC Controllers & Views in same project
问题
Started with the ASP.Net Core with React (v6.0) template and am trying to add MVC Controllers & Views.
Have Added services.AddControllersWithViews() in ConfigureServices and the following is my Configure code:
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/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.UseEndpoints(endpoints =>
{
// Catchall Route for our API Controllers
endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action}/{id?}");
});
app.Run();
I can call API Controllers (i.e. weatherforecast and sample api) but when I add HomeController and then add /Views/Home/Index.cshtml I can never get it to route to the razor page - only api calls work.
I cannot find an example that shows both MVC Views and React Spa running in the same solution.
TIA!
英文:
Started with the ASP.Net Core with React (v6.0) template and am trying to add MVC Controllers & Views.
Have Added services.AddControllersWithViews() in ConfigureServices and the following is my Configure code:
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/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.UseEndpoints(endpoints =>
{
// Catchall Route for our API Controllers
endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action}/{id?}");
});
app.Run();
I can call API Controllers (i.e. weatherforecast and sample api) but when I add HomeController and then add /Views/Home/Index.cshtml I can never get it to route to the razor page - only api calls work.
I cannot find an example that shows both MVC Views and React Spa running in same solution.
TIA!
答案1
得分: 1
只返回翻译好的部分:
"OK folks... the key here is to simply include the MVC routes in the setupProxy.js"
翻译成中文为:
"好的,各位...关键是在setupProxy.js中简单地包含MVC路由。"
英文:
OK folks... the key here is to simply include the MVC routes in teh setupProxy.js
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论