I have referred few question (Q1, Q2) regarding this question but I think mine is little different.
I have created a login page and on successful login it should open Index view of home controller. As my index view requires a model to bind table data I need to pass the model object along with view in login button action. I hope you get the scenario.
Here's my LoginController
:
public ActionResult Login() // Get method for Login
{
return View("Login");
}
[HttpPost] // Post method on Login
public ActionResult Defaults(string username, string password)
{
FloorFactor ff = new FloorFactor(); // tried to create model object to pass in view
try
{
Login_Details login_detail = db.Login_Details.Single(x => (x.UserName == username) && (x.Password == password));
if (login_detail != null)
{
return View("../Home/Index",ff ); // need to get view Index of home controller.
}
}
catch { }
return View("Login");
}
Required part of Index.cshtml
:
@model IEnumerable<Pricing_Tool_Test.FloorFactor>
@{
ViewBag.Title = "Index";
}
Error:
I know model required IEnumerable
kind of model object but in my defaults method it doesn't allow me to pass IEnumerable
object of model.
Can anyone help? How can I achieve this?
Edit: both controllers are different. Login button needs to load view of HomeController
. It generates exception shown in the screenshot, if I comment that line than it generates error mentioned above:
EDIT 2: Home/Create Coding
public PartialViewResult Create()
{
return PartialView("_CreatePartial");
}
// POST: Home/Create
[HttpPost]
public ActionResult Create([Bind(Include = "FloorFactorPercentage,FromDate,ToDate")]FloorFactor floorfactor)
{
if (ModelState.IsValid)
{
db.FloorFactors.Add(floorfactor);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(floorfactor);
}