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!