繁体   English   中英

区域 asp.net cor mvc 的 Url.Action

[英]Url.Action for area asp.net cor mvc

Javascript代码:

<script type="text/javascript">

              url = '/Masters/GLMaster/SearchGLPartial';
               // url='@Url.Action("SearchGLPartial", "GLMaster")';
               
                let name = document.getElementById("Name").value;
                let code = document.getElementById("Code").value;
             

                var data = { "Name": name, "Code": code};
                var o = Object.keys(data).map(k => k + "=" + encodeURIComponent(data[k])).join("&")
               
              var resulturl=url + "?" + o;


    ...other code

</script>

如果我将硬编码的 url 更改为以下代码

url='@Url.Action("SearchGLPartial", "GLMaster", new { area = "Masters" })';

我的没有区域的代码工作正常。它生成带有参数的 url..

但是对于区域不起作用

当前结果:(网址)

  '/GLMaster/SearchGLPartial?area=Masters';

我还需要附加附加参数..它是冲突的

预期输出: 'Masters/GLMaster/SearchGLPartial';

编辑:

我的端点路由配置:

 app.UseEndpoints(endpoints =>
            {
            
                endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=LandPage}/{id?}");
                endpoints.MapControllerRoute( name: "areas", pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
             

                                
            });

更改路线模板的顺序,如下所示:

app.UseEndpoints(endpoints =>
{         
     endpoints.MapControllerRoute( name: "areas", pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
     endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=LandPage}/{id?}");                               
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM