0

I'm using MVC3. I have a ActionLink in my home page, which will redirect to another dueItem page:

@Html.ActionLink("Due Items", "Reports", "Reports", null, new { @class = "btn btn-sm btn-outline-secondary", @style = "color:black; font-size: 15px;" })

The controller & model of dueItem page are below:
Model:

 public class ViewModel
{        
    public IEnumerable<InvHardwareModel>Report_HardwareListByExpiration { get; set; }

}

Controller:

public class ReportsController : Controller
{
    // GET: Report
    public ActionResult Reports()
    {
        if (Session["UserID"] == null || !(bool)Session["IsLoggedIn"])
        {
            return RedirectToAction("Login", "Account");
        }
        ViewModel myViewModel = new ViewModel
        {
            User = GetSessionInfoFromSessions(),
            Params = new ParametersModel
            {
                Start_Date = new DateTime(2015, 12, 31),
                End_Date   = DateTime.Now.AddDays(60)
            }
        };

        myViewModel.Report_HardwareListByExpiration = InvHardwareModel.Report_HardwareListByExpiration(myViewModel);
                 
        
        return View(myViewModel);
    }

Now I want to remove this ActionLink and copy the code to my home page directly, but after I run the project it has a error: Error page

My home page are using different controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {            
        if (Session["UserID"] == null || !(bool)Session["IsLoggedIn"])
        {
            return RedirectToAction("Login", "Account");
        }
        var myViewAgModel = new ViewModel();
        //Populate ViewModel that goes into Dashboards and Reports.
        myViewAgModel.User = GetSessionInfoFromSessions();

        var InvHardwareModel =new InvHardwareModel();           
        ViewBag.InvHardwareTotalPrice = InvHardwareModel.InvHardwareBalance(GetSessionInfoFromSessions(), true);
        ViewBag.InvHardwareTotal = InvHardwareModel.InvHardwareCount(GetSessionInfoFromSessions(), true);

        //myViewAgModel.Report_HardwareListByExpiration = InvHardwareModel.Report_HardwareListByExpiration(myViewAgModel);
       
        return View(myViewAgModel);
       
    }

Thanks!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Acadia
  • 1
  • 3
  • Something like this ? https://stackoverflow.com/a/50777301/1866810 – AlexB Jan 12 '23 at 13:47
  • Hi @AlexB, thanks for your advice, I searched and find your answer on this link yesterday, but unfortunately it not works for me, it still shows the error page after I put those code under my homeController. – Acadia Jan 12 '23 at 13:57
  • " it still shows the error page" => On which line of code does it crash ? – AlexB Jan 12 '23 at 14:07
  • This is the error page link, I also asked this question first https://stackoverflow.com/questions/75073599/object-reference-not-set-to-an-instance-of-an-object-error-when-trying-to-move thank you for your time – Acadia Jan 12 '23 at 14:10

0 Answers0