For complete understanding I uploaded the source code
https://1drv.ms/u/s!AsYYSVzzwhqzgYIZERqI18BzSi52Jg
public void RegisterRoutes(RouteCollection routes) {
routes.MapRoute("HandelRegister",
"handelregister",
new { controller = "Handel", action = "HandelRegister" },
new[] { "Nop.Plugin.Misc.Handel.Controllers" });
using System.Web.Routing;
using Nop.Core.Plugins;
using Nop.Services.Common;
namespace Nop.Plugin.Misc.Handel {
public class HandelPlugin : BasePlugin, IMiscPlugin
{
public override void Install() {
base.Install();
}
public override void Uninstall() {
base.Uninstall();
}
public void GetConfigurationRoute(out string actionName, out string controllerName, out System.Web.Routing.RouteValueDictionary routeValues)
{
actionName = "Configure";
controllerName = "Handel";
routeValues = new RouteValueDictionary { { "Namespaces", "Nop.Plugin.Misc.Handel.Controllers" }, { "area", null } };
}
}
}
using Nop.Plugin.Misc.Handel.Infrastructure;
using Nop.Web.Framework.Mvc.Routes;
using System;
using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Localization;
namespace Nop.Plugin.Misc.Handel {
public partial class RouteConfig : IRouteProvider
{
public int Priority {
get {
return 0;
}
}
public void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("HandelRegister",
"HandelRegister/",
new { controller = "Handel", action = "HandelRegister" },
new[] { "Nop.Plugin.Misc.Handel.Controllers" });
// ViewEngines.Engines.Insert(0, new CustomViewEngine());
}
}
}
using Nop.Web.Models.Customer;
using Nop.Web.Framework.Controllers;
using System.Web.Mvc;
namespace Nop.Plugin.Misc.Handel.Controller {
public partial class HandelController : BasePluginController {
public ActionResult HandelRegister() {
var model = new RegisterModel();
return View("~/Plugins/Misc.Handel/Views/HandelRegister.cshtml", model);
}
}
}
@if(Model.GenderEnabled) {
@if(Model.GenderEnabled) {
[NopHttpsRequirement(SslRequirement.Yes)]
//available even when navigation is not allowed
[PublicStoreAllowNavigation(true)]
public ActionResult Register()
{
//check whether registration is allowed
if (_customerSettings.UserRegistrationType == UserRegistrationType.Disabled)
return RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Disabled });
var model = new RegisterModel();
PrepareCustomerRegisterModel(model, false); //bind data with model
//enable newsletter by default
model.Newsletter = _customerSettings.NewsletterTickedByDefault; //bind data with model
return View(model);
}
[NonAction]
protected virtual void PrepareCustomerRegisterModel(RegisterModel model, bool excludeProperties,
string overrideCustomCustomerAttributesXml = "")
{
if (model == null)
throw new ArgumentNullException("model");
model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone;
foreach (var tzi in _dateTimeHelper.GetSystemTimeZones())
model.AvailableTimeZones.Add(new SelectListItem { Text = tzi.DisplayName, Value = tzi.Id, Selected = (excludeProperties ? tzi.Id == model.TimeZoneId : tzi.Id == _dateTimeHelper.CurrentTimeZone.Id) });
model.DisplayVatNumber = _taxSettings.EuVatEnabled;
//form fields
model.GenderEnabled = _customerSettings.GenderEnabled;
model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled;
model.DateOfBirthRequired = _customerSettings.DateOfBirthRequired;
model.CompanyEnabled = _customerSettings.CompanyEnabled;
model.CompanyRequired = _customerSettings.CompanyRequired;
model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled;
model.StreetAddressRequired = _customerSettings.StreetAddressRequired;
model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled;
model.StreetAddress2Required = _customerSettings.StreetAddress2Required;
model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled;
model.ZipPostalCodeRequired = _customerSettings.ZipPostalCodeRequired;
model.CityEnabled = _customerSettings.CityEnabled;
model.CityRequired = _customerSettings.CityRequired;
model.CountryEnabled = _customerSettings.CountryEnabled;
model.CountryRequired = _customerSettings.CountryRequired;
model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled;
model.StateProvinceRequired = _customerSettings.StateProvinceRequired;
model.PhoneEnabled = _customerSettings.PhoneEnabled;
model.PhoneRequired = _customerSettings.PhoneRequired;
model.FaxEnabled = _customerSettings.FaxEnabled;
model.FaxRequired = _customerSettings.FaxRequired;
model.NewsletterEnabled = _customerSettings.NewsletterEnabled;
model.AcceptPrivacyPolicyEnabled = _customerSettings.AcceptPrivacyPolicyEnabled;
model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
model.CheckUsernameAvailabilityEnabled = _customerSettings.CheckUsernameAvailabilityEnabled;
model.HoneypotEnabled = _securitySettings.HoneypotEnabled;
model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnRegistrationPage;
model.EnteringEmailTwice = _customerSettings.EnteringEmailTwice;
//countries and states
if (_customerSettings.CountryEnabled)
{
model.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" });
foreach (var c in _countryService.GetAllCountries(_workContext.WorkingLanguage.Id))
{
model.AvailableCountries.Add(new SelectListItem
{
Text = c.GetLocalized(x => x.Name),
Value = c.Id.ToString(),
Selected = c.Id == model.CountryId
});
}
if (_customerSettings.StateProvinceEnabled)
{
//states
var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId, _workContext.WorkingLanguage.Id).ToList();
if (states.Any())
{
model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource("Address.SelectState"), Value = "0" });
foreach (var s in states)
{
model.AvailableStates.Add(new SelectListItem { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) });
}
}
else
{
bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected);
model.AvailableStates.Add(new SelectListItem
{
Text = _localizationService.GetResource(anyCountrySelected ? "Address.OtherNonUS" : "Address.SelectState"),
Value = "0"
});
}
}
}
//custom customer attributes
var customAttributes = PrepareCustomCustomerAttributes(_workContext.CurrentCustomer, overrideCustomCustomerAttributesXml);
customAttributes.ForEach(model.CustomerAttributes.Add);
}