传递到字典中的模型项的类型为'System.Collections.Generic.List`1 [英] The model item passed into the dictionary is of type 'System.Collections.Generic.List`1

查看:198
本文介绍了传递到字典中的模型项的类型为'System.Collections.Generic.List`1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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'.
















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");
        }

    }
}





###嗨......我我是MVC的新伙伴......就在1天之前......我开始......我需要建议解决这个问题以及如何快速学习MVC ....

***数十亿在此先感谢



###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

推荐答案





我认为你犯了同样的错误类型的模型,所以你应该传递视图如





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





如果您想从头学习MVC,可以查看以下链接:



https://www.youtube.com/playlist?list=PL33C9E91F8CDD2BF7 [ ^ ]


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>


这篇关于传递到字典中的模型项的类型为'System.Collections.Generic.List`1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆