Topic
@foreach (var topic in Model.Topics.Where(x => x.IncludeInFooterColumn1).ToList())
{
<li class="nav-item"><a class="nav-link" href="@Url.RouteUrl("Topic", new { SeName = topic.SeName })">@topic.Name</a></li>
}
https://stackoverflow.com/questions/64076294/i-want-to-allow-forward-slash-into-sename
ContactUs
step 1:注册路由
ContactUs指向CommonController控制器的ContactUs()方法
src/Presentation/Nop.Web/Infrastructure/RouteProvider.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Nop.Web.Framework.Localization;
using Nop.Web.Framework.Mvc.Routing;
namespace Nop.Web.Infrastructure
{
/// <summary>
/// Represents provider that provided basic routes
/// </summary>
public partial class RouteProvider : IRouteProvider
{
#region Methods
/// <summary>
/// Register routes
/// </summary>
/// <param name="routeBuilder">Route builder</param>
public void RegisterRoutes(IRouteBuilder routeBuilder)
{
//reorder routes so the most used ones are on top. It can improve performance
...
routeBuilder.MapLocalizedRoute("ContactUs", "contactus",
new { controller = "Common", action = "ContactUs" });
...
} }
2.控制器
src\Presentation\Nop.Web\Controllers\CommonController.cs
namespace Nop.Web.Controllers
{
public partial class CommonController : BasePublicController
{
...
public virtual IActionResult ContactUs()
{
var model = new ContactUsModel();
model = _commonModelFactory.PrepareContactUsModel(model, false);
return View(model);
}
..
}
调用CommonModelFactory只是用来准备Model 数据,一边显示
src/Presentation/Nop.Web/Factories/CommonModelFactory.cs
public virtual ContactUsModel PrepareContactUsModel(ContactUsModel model, bool excludeProperties)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (!excludeProperties)
{
model.Email = _workContext.CurrentCustomer.Email;
// model.FullName = _customerService.GetCustomerFullName(_workContext.CurrentCustomer);
model.FullName = _workContext.CurrentCustomer.Username;
}
//出错
//model.SubjectEnabled = _commonSettings.SubjectFieldOnContactUsForm;
//model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
//改成下面的
var commonSettings = _settingService.GetSetting<CommonSettings>();
var captchaSettings = _settingService.GetSetting<CaptchaSettings>();
model.SubjectEnabled = _commonSettings.SubjectFieldOnContactUsForm;
model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
return model;
}
step 3:VIEW
src/Presentation/Nop.Web/Views/Common/ContactUs.cshtml
step 4:主页生成的连接
<li><a href="@Url.RouteUrl("ContactUs")">@T("ContactUs")</a></li>