I have encountered a situation where I am having difficulty fixing an issue with my DevExpress MVC components, specifically the treeview. Even though this is a common problem with numerous solutions available online, none of them seem to work in my specific scenario.
The code for the treeview looks like this:
@Html.DevExpress().TreeView(settings =>
{
settings.Name = "NavigationClientsList";
settings.AllowSelectNode = true;
Model.ForEach(_client =>
{
settings.Nodes.Add(node =>
{
node.Name = String.Format("{0}_client_{1}", settings.Name, _client.ClientID);
node.Text = _client.ClientName;
});
});
settings.ClientSideEvents.NodeClick = "OnTreeViewNodeClick";
settings.PreRender = (source, e) =>
{
ASPxTreeView treeView = (ASPxTreeView)source;
treeView.ExpandAll();
};
}).GetHtml()
Here's the function for handling the NodeClick event:
function OnTreeViewNodeClick(s, e) {
if (e.node.name.indexOf("_client_") > -1) {
var tmpDivDescription = e.node.name.split("_");
if (tmpDivDescription.length = 3) {
var tmpID = tmpDivDescription[2];
$.ajax({
url: 'Home/Client/',
data: { 'id': tmpID },
dataType: "html",
success: function (result) {
$("#DataDisplay").html(result);
},
error: function (xhr) { alert('ERROR!' + xhr.responseText) }
});
}
} else {
}
}
I have tried using two different ways to perform the Ajax call:
url: 'Home/Client/'
and
url: '@Url.Action("Client", "Home")'
While the first method works as expected, the server responds with a resource not found error when attempting to use the second method with UrlAction:
Description: HTTP 404. The requested resource or one of its dependencies may have been removed, renamed, or temporarily unavailable. Requested URL: /@Url.Action("Client", "Home")
The requested URL seems to include an extra "/", which might be causing the issue. Most resources suggest using the "normal" Url.Action format, but it doesn't seem to work for me. Any insights on how to resolve this?