没有类型为“ IEnumerable <selectlistitem>”的具有键“ pkiBusinessUnitId”的ViewData项目

时间:2018-09-05 14:47:55

标签: asp.net-mvc

我已经阅读了很多错误相同的帖子,但似乎没有一个是相同的情况(或者我错了)。

我正在选择除dropdownlist以外的所有详细信息,并且收到此错误消息。下拉列表中确实有数据。

DropDownListFor:

@Html.DropDownListFor(model => model.fkiBusinessUnitId, Model._BUList, "-- Select Business Unit --", null)<i></i>

控制器:

// POST: /account/register
        [HttpPost]
        [AllowAnonymous]
        //[ValidateAntiForgeryToken]
        public async Task<ActionResult> Register(AccountRegistrationModel model)
        {
            if (ModelState.IsValid)
            {
                RecaptchaApiResponse response = ValidateCaptcha(Request["g-recaptcha-response"]);

                if (!response.Success)
                {
                    //Captcha Code Failed
                    ModelState.AddModelError("", "Error From Google ReCaptcha : " + response.ErrorMessage[0].ToString());
                    clsBusinessUnit clsBusinessUnit = new clsBusinessUnit();
                    model._BUList = clsBusinessUnit.GetBusinessUnits();
                    return View(model);
                }

                if(model.fkiBusinessUnitId == 0 || model.fkiBusinessUnitId == null){
                    ModelState.AddModelError("", "No Business Unit Selected");
                    clsBusinessUnit clsBusinessUnit = new clsBusinessUnit();
                    model._BUList = clsBusinessUnit.GetBusinessUnits();
                    return View(model);
                }

                if (!model.bDisplayGender)
                {
                    model.Gender = "Not Specified";
                }

                var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName,
                                                 profile_picture_url = "https://viima-app.s3.amazonaws.com/media/public/defaults/user-icon.png", DOB = model.DOB,
                                                 fkiBusinessUnitId = model.fkiBusinessUnitId, Gender = model.Gender };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);

            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

在模型中:

[DefaultValue(0)]
        public int? fkiBusinessUnitId { get; set; }
        public IEnumerable<System.Web.Mvc.SelectListItem> _BUList { get; set; }

请随时告诉我我很愚蠢,因为我确定我在这里确实缺少一些基本知识。但是任何人都可以帮助解决这个问题吗?

谢谢!

0 个答案:

没有答案