In a single razor view, how can i retrieve values passed from different methods of a controller?

前端 未结 1 588
深忆病人
深忆病人 2021-01-22 17:23

I\'m working on a basic application.

This is the main controller:

   public ActionResult Index()
    {
        var all = _context.mainz.ToList();
                


        
相关标签:
1条回答
  • 2021-01-22 17:43

    Use ViewBag or ViewData to pass any kind of information when you are bounded to one Model.

    • ViewBag is dynamic : @ViewBag. - just fill data in controller and you will have it in view.

    • ViewData - is a dictionary and use is ViewData["any_name"]

    Of course appropriate casting is required in a view.

    If you want to store global variable accessed to all views then it is on application level :

     Application["Counter"] = 1234;
    

    Also you can pass model to partial :

    @Html.Partial("count", Model)
    
    0 讨论(0)
提交回复
热议问题