0

This is my code:

 public class StoreController:Controller
    {
        public ActionResult Index()
        {
            var page=new PageHelper<Store>();          
            return page.PageView(this);
        }
    }   
    public class PageHelper<T>
    {
        public List<T>DataSouce {get;set;}  
        public ActionResult PageView(Controller controller)
        {
            var action = controller.RouteData.Values["action"].ToString();
            if (controller.Request.IsAjaxRequest())
                //my question is it can not call the PartialView or controller.View 
                return controller.PartialView(action);               
            return controller.View(DataSource);
        }
    }  

I can not call the PartialView or controller.View in PageView function. how I can do it?

now this code:"controller.PartialView(action);" in PageView function will be compiled error. why can not call the View() or PartialView()?

tereško
  • 58,060
  • 25
  • 98
  • 150
tiancaolin
  • 43
  • 8

1 Answers1

1

View and PartialView are protected internal methods.

The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly.

you should make your class PagerHelper inherit from Controller.

After that you can call inside your PageView method

public ActionResult PageView(Controller controller)
    {        
        ViewBag.DataSource = DataSource;
        ViewBag.PageHtml = PageHtml;
        ViewBag.AjaxPageHtml = AjaxPageHtml;

        if (controller.Request.IsAjaxRequest())
            return PartialView(AjaxTag);          
        var action = controller.RouteData.Values["action"].ToString();
        return View(action);         
    } 

I have tested your project and now it works.

faby
  • 7,394
  • 3
  • 27
  • 44
  • really? about "class PagerHelper inherit from Controller" I have test it before I submit my question on the stackoverflow. can you send your changes to my email. my email is :chuanhai@outlook.com – tiancaolin May 12 '14 at 15:22
  • I've tryed to send you the mail but it return back to me with an error (mailbox unavailable). – faby May 12 '14 at 15:28
  • Remember that you must not only ensure that the class inherits from Controller. You must also change controller.PartialView with PartialView without controller variable. – faby May 12 '14 at 15:35
  • oh, I make a mistake! my Email is: linchuanhai@outlook.com. I'am sorry. can you send it again. I will wating for you online. – tiancaolin May 12 '14 at 15:47
  • thank you for your mail. I read your changes. but all like your changes I have try it before. of course now It is Compile success. but it can not work. can you run it to see the page result? – tiancaolin May 12 '14 at 16:16