2012-10-12 6 views
1

나는 두 개의 컨트롤러가 있습니다. > CheckData 기능, 나는 CatalogController 전화를 걸 - -MVC에서 다른 컨트롤러 기능을 호출하는 방법은 무엇입니까?

하나가 다른 하나

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

     } 
} 

내부 컨트롤러를 대여입니다

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

} 
} 

입니다 을> PrepareProductOverviewModels (...)를 어떻게 할 수 해??

답변

3

이것은 protected이므로 HireControllerCatalogController에서 파생되지 않으면 호출 할 수 없습니다. 경우, 그러나, 당신은 이러한 뷰 모델 클래스로, 다른 클래스에 넣어, 그것은 public, 당신이 당신의 HireController에서 호출 할 수 있습니다합니다.

그것은 그 뷰 모델이 protected 수 또는 당신의 컨트롤러 클래스에 있어야 할 할 거의 의미가 있습니다. 당신이 컨트롤러 사이에 공유 될 필요가 방법이있는 경우

0

다음은 「헬퍼」클래스에 사람들을 분리하고 두 컨트롤러가 그 클래스를 호출해야한다.

관련 문제