How to create a second register

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 лет назад
For complete understanding I uploaded the source code

https://1drv.ms/u/s!AsYYSVzzwhqzgYIZERqI18BzSi52Jg
7 лет назад
FlorianNeiss wrote:
I am using nopCommerce 3.8
But when I try to access my HandelRegister.cshtml i get following error.

http://imgur.com/a/HySQA

write only controller name part like bellow==>

controller = "Handel"



public void RegisterRoutes(RouteCollection routes) {
            routes.MapRoute("HandelRegister",
            "handelregister",
            new { controller = "Handel", action = "HandelRegister" },
            new[] { "Nop.Plugin.Misc.Handel.Controllers" });


And I think don't need "CustomViewEngine"



Thank you for your fast reply.

I am still getting the same error. After changing the bug in route.



Clear cache from Admin and restart the application. if faces again knock me
7 лет назад
Updated version of my code.

The RouteConfig was wrong.

https://1drv.ms/u/s!AsYYSVzzwhqzgYIaYwuhDMLcIkrV3w
7 лет назад
sohel wrote:


Clear cache from Admin and restart the application. if faces again knock me



I always rebuild my solution in VS 2015
In chrome i press Ctrl + R to reset cache.

And now in addition I cleared cache as admin.

Still same error.
7 лет назад
FlorianNeiss wrote:


Clear cache from Admin and restart the application. if faces again knock me


I always rebuild my solution in VS 2015
In chrome i press Ctrl + R to reset cache.

And now in addition I cleared cache as admin.

Still same error.


Did you restart application?
7 лет назад
I am still getting 404 when I try to access my HandelRegister.cshtml.

When I uninstall the plugin. I get the normal nopCommerce 404.
When I install the plugin I get the crazy error 404 as in the picture posted earlier.

This is really the smallest and simpliest plugin.

1 route
1 costum page (HandelRegister.cshtml)

But still I can't access it.

Please help me.
7 лет назад
Try the following ==> These modificatin hit your route
Note: make the classes public
1.HandelPlugin.cs

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 } };

        }
     }
}



2. RouteConfig.cs


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());
        }
    }
}



3. HandelController.cs


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);
        }
    }
}
7 лет назад
Yes thanks,

now my cshtml page is accessable.
7 лет назад
Hi,

my new problem is:

I don't get any data from the registermodel. It seems it is null.

I've uploaded my plugin

https://1drv.ms/u/s!AsYYSVzzwhqzgYQ33-1GygSpHURP9w

I want to make my own register.
That means I have to use the registermodel.

In the picture is no gender option, because in the code of the handelregister.cshtml is this section.

@if(Model.GenderEnabled) {


That is why I think the model is null.

How can I get the model...or how am I able to access the data of it?

http://imgur.com/a/4WrEh
7 лет назад
FlorianNeiss wrote:
Hi,

my new problem is:

I don't get any data from the registermodel. It seems it is null.

I've uploaded my plugin

https://1drv.ms/u/s!AsYYSVzzwhqzgYQ33-1GygSpHURP9w

I want to make my own register.
That means I have to use the registermodel.

In the picture is no gender option, because in the code of the handelregister.cshtml is this section.

@if(Model.GenderEnabled) {


That is why I think the model is null.

How can I get the model...or how am I able to access the data of it?

http://imgur.com/a/4WrEh


You need must bind data with model before passing view===>
Go through how current register work
CustomerController.cs
Nop.Web.Controllers


  [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);
        }

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.