How can I find a ModelView that is case-insensitive? FindModelView is case-sensitive.
Web - How to support case-insensitive URLs
Answers approved by DevExpress Support
Thank you for your clarification, Mario. In XAF, Contact_ListView and contact_ListView are two different valid view IDs. As a result, the FindModelView method should be case-sensitive. However, starting with version 19.1, you can create a custom IViewUrlManager to support case-insensitive URLs. For example, your CustomViewUrlManager may look like:
C#using System;
using System.Collections.Generic;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Web;
namespace FriendlyUrlSample.Web {
public class CustomViewUrlManager : IViewUrlManager {
private IViewUrlManager innerViewUrlManager;
Dictionary<string, string> viewIds = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
public CustomViewUrlManager() {
innerViewUrlManager = new ViewUrlManager();
foreach(var view in WebApplication.Instance.Model.Views) {
viewIds.Add(view.Id, view.Id);
}
}
public string GetUrl(ViewShortcut shortcut, IDictionary<string, string> additionalParams = null) {
return innerViewUrlManager.GetUrl(shortcut, additionalParams);
}
public ViewShortcut GetViewShortcut() {
ViewShortcut shortcut = innerViewUrlManager.GetViewShortcut();
if(viewIds.ContainsKey(shortcut.ViewId)) {
shortcut.ViewId = viewIds[shortcut.ViewId];
}
return shortcut;
}
}
}
Please test this solution on your side to check if it provides you with the required behavior.
Hi Mario,
Would you please elaborate on what you mean by a case-insensitive ModelView? The XafApplication.FindModelView method is used to find a view by its ID. IDs are case-sensitive. MyObject_ListView and Myobject_ListView are different views. Which view do you wish to get by using the FindModelView method if it was case-insensitive?
I am building my own CustomRouteManager for version 19.1. In GetViewShortcut I have to find the right ViewId. That wouldn't be a problem, but the urls are all lower case. Thus the ViewId is also written in lower case in ViewShortcut.
Now my idea was to find the suitable IModelView and to read out the correct ViewId from it.
https://github.com/DevExpress-Examples/friendly-url-sample/blob/master/VB/FriendlyUrlSample.Web/CustomRouteManager.vb
This is the case when lower case is forced for all urls.
routes.LowercaseUrls = True
This is necessary in my project because I use XAF together with other websites. XAF is accessible via /admin/.
BrowserHistoryMode = BrowserHistoryMode.FriendlyUrl