Answer the question
In order to leave comments, you need to log in
Prefix route in Razor Pages: how to organize link generation?
I have the following problem: I need to create two different routes in Razor Pages. The first - standard, the second - with a prefix for example simple.
I do it this way: I implement the IPageRouteModelConvention interface and add my template with the simple prefix
public class SimplePageRouteModelConvention : IPageRouteModelConvention
{
public void Apply(PageRouteModel model)
{
var selectorCount = model.Selectors.Count;
for (var i = 0; i < selectorCount; i++)
{
var selector = model.Selectors[i];
model.Selectors.Add(new SelectorModel
{
AttributeRouteModel = new AttributeRouteModel
{
Template = AttributeRouteModel.CombineTemplates("simple", selector.AttributeRouteModel.Template)
}
});
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question