我正在尝试在我的 razor 页面中使用 @Html.ActionLink 和 @Url.Action。
为此,我的 View 中有以下代码
<div Id="SetLanguageUrl" value="@Url.Action("SetLanguage", "Language")"></div>
@Html.ActionLink("Test", "SetLanguage", "Language")
我没有收到错误,但两者都没有解析 URL,如浏览器开发工具屏幕截图中所示。
有人知道我可能会错过什么吗?
最佳答案
好吧,这非常令人沮丧,但这是解决方案。
在 Startup.cs - 配置中我有以下内容:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
当我将其更改为:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
看起来有效。
关于asp.net-mvc - @Html.ActionLink、@Url.Action 在 asp.net core razor View 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67791698/