1

I have two controllers.

one is

 public partial class CatalogController : BaseNopController
    {

 [NonAction]
        protected IEnumerable<ProductOverviewModel> PrepareProductOverviewModels(IEnumerable<Product> products, 
            bool preparePriceModel = true, bool preparePictureModel = true,
            int? productThumbPictureSize = null, bool prepareSpecificationAttributes = false,
            bool forceRedirectionAfterAddingToCart = false)
        {
 var models = new List<ProductOverviewModel>();
            foreach (var product in products)
            {
                var model = new ProductOverviewModel()
                {
                    Id = product.Id,
                    Name = product.GetLocalized(x => x.Name),
                    ShortDescription = product.GetLocalized(x => x.ShortDescription),
                    FullDescription = product.GetLocalized(x => x.FullDescription),
                    SeName = product.GetSeName(),
                };

}
}

another one is

public class HireController : BaseNopController
    {

        [HttpPost]
        public ActionResult CheckData(string submitButton)
        {
            switch (submitButton)
            {
                case "Yes":

                   // I want to call  CatalogController  --> PrepareProductOverviewModels
                case "No":
                    return RedirectToRoute("detailform");
                default:
                    return RedirectToRoute("detailform");
            }

        }
}

Inside Hire controller --> CheckData function , I want to call CatalogController -->PrepareProductOverviewModels(...) How can I do it??

2 Answers 2

3

It's protected, so unless your HireController derives from CatalogController, you can't call it. If, however, you put it in another class, such as a ViewModel class, and make it public, you can call it from your HireController.

It makes very little sense for that ViewModel to be protected or for it to be in your controller class.

Sign up to request clarification or add additional context in comments.

Comments

0

If you have methods that need to be shared between controllers then you should separate those out to a "helper" class and have both controllers call into that class.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.