Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Server Error in '/' Application.

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MVCLoginForm.Models.ModalLogin]', but this dictionary requires a model item of type 'MVCLoginForm.Models.ModalLogin'.





C#
namespace MVCLoginForm.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/
        ModalLogin Mod2 = new ModalLogin();
        static List<ModalLogin> Mod = new List<ModalLogin>();
        
        public ActionResult Index()
        {
            return View(Mod);
        }
        public ActionResult Record()  //error in this plz solve
        {
            Mod.Add(Mod2);            //error
            return View(Mod);         //error
        }
        public ActionResult Login()
        {
            return View();
        }
         [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Login(ModalLogin Mod1)
        {
            if (!ModelState.IsValid)
            {
                return View("Login", Mod1);
            }
            Mod.Add(Mod1);
            return RedirectToAction("Index");
        }

    }
}


###Hi ...I am a new buddy in MVC...just before 1 day...I started..Plz i need advice to solve this and how to learn MVC Quickly....
***Billions of Thanks in advance
Posted
Updated 17-Aug-15 20:38pm
v2

hi,

I think you have done same mistake you are passing an list type of model so you should pass in view like

@model List<modallogin>


if you need single model then pass

@model modalLogin


and if you want to learn MVC from scratch you can view below link:

https://www.youtube.com/playlist?list=PL33C9E91F8CDD2BF7[^]
 
Share this answer
 
v4
Comments
harshil gandhi 18-Aug-15 3:22am    
I used List<modallogin>..in above example....
harshil gandhi 18-Aug-15 3:25am    
Hey My error is solved.... when i debug it....
But the Problem is i am using UserId, Password and EmailId...in Register Page...
and those details will come in...Index page as a record....When i click those details...It will redirects to Record.aspx page...Details are coming but the problem is Password is coming as 0....Plz Help...Thanks in advance...
Refer http://www.c-sharpcorner.com/UploadFile/cd3310/using-mvc-Asp-Net-tools-create-simple-login-form/
Suket shah 18-Aug-15 4:28am    
ok that's great.

please resolve issue so no one will stuck
harshil gandhi 18-Aug-15 4:40am    
But the Problem is i am using UserId, Password and EmailId...in Register Page...
and those details will come in...Index page as a record....When i click those details...It will redirects to Record.aspx page...Details are coming but the problem is Password is coming as 0....Plz Help...Thanks in advance...
efer http://www.c-sharpcorner.com/UploadFile/cd3310/using-mvc-Asp-Net-tools-create-simple-login-form/
C#
namespace MVCLoginForm.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/
        ModalLogin Mod2 = new ModalLogin();
        static List<modallogin> Mod = new List<modallogin>();
        
        public ActionResult Index()
        {
            return View(Mod);
        }
        public ActionResult Record(ModalLogin Mod3) //solved 
        {
            
            return View(Mod3);  //solved        
        }
        public ActionResult Login()
        {
            return View();
        }
         [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Login(ModalLogin Mod1)
        {
            if (!ModelState.IsValid)
            {
                return View("Login", Mod1);
            }
            Mod.Add(Mod1);
            return RedirectToAction("Index");
        }
 
    }
}
</modallogin></modallogin>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900