Reputation: 331
Javascript code:
<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>
If i changed harcoded url to below code
url='@Url.Action("SearchGLPartial", "GLMaster", new { area = "Masters" })';
My code without area is working fine.It generate url with parameter..
But for Area is not working
Current Result:( url)
'/GLMaster/SearchGLPartial?area=Masters';
I also need to append additinal paramter ..it is conflicting
Expected output:'Masters/GLMaster/SearchGLPartial';
EDIT:
My End Point Routing Config:
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?}");
});
Upvotes: 2
Views: 545
Reputation: 36705
Change the order of your route template like below:
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?}");
});
Upvotes: 1