我有兩個控制器。如何在MVC中調用另一個控制器函數?
一個是
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(),
};
}
}
另一個是
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");
}
}
}
內部服務控制器 - > CheckData功能,我想打電話給CatalogController - > PrepareProductOverviewModels(...) 我怎樣才能這樣做?