-1
私はAsp.net MVC5の学習を始めたばかりで、次の行にArgumentNullException
が表示されています。MVC5のArgumentNullException DropdownListFor
@Html.DropDownListFor(m => m.Customer.MembershipTypeId, new SelectList(Model.MembershipTypes, "Id", "Name"), "", new { @class = "form-control" })
私はチュートリアルを以下だと私はので、私はそれがこのエラーを投げ、なぜわからないんだけど、それはまったく同じです。 モデルとテーブルのデータを見て、それらのデータが読み込まれました。 この問題を理解するために追加情報が必要かどうかお知らせください。
New.cshtml
@model Vidly6.VIewModel.NewCustomerViewModel
@{
ViewBag.Title = "New";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>New Customer</h2>
@using (Html.BeginForm("Create", "Customers"))
{
<div class="form-group">
@Html.LabelFor(m => m.Customer.Name)
@Html.TextBoxFor(m => m.Customer.Name, new {@class = "form-control"})
</div>
<div class="form-group">
@Html.LabelFor(m => m.Customer.BirthDate)
@Html.TextBoxFor(m => m.Customer.BirthDate, new {@class = "form-control"})
</div>
<div class="checkbox">
<label>
@Html.CheckBoxFor(m=>m.Customer.IsSubscribedToNewsletter) Subscribed to Newsletter?
</label>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Customer.MembershipTypeId)
@Html.DropDownListFor(m => m.Customer.MembershipTypeId, new SelectList(Model.MembershipTypes, "Id", "Name"), "", new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Customer.MembershipTypeId)
</div>
}
NewCustomerViewModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Vidly6.Models;
namespace Vidly6.VIewModel
{
public class NewCustomerViewModel
{
public IEnumerable<MembershipTypes> MembershipTypes { get; set; }
public Customers Customer { get; set; }
}
}
CustomersController
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vidly6.Models;
using Vidly6.VIewModel;
namespace Vidly6.Controllers
{
public class CustomersController : Controller
{
private ApplicationDbContext _context;
public CustomersController()
{
_context = new ApplicationDbContext();
// GET: Customers
}
protected override void Dispose(bool disposing)
{
_context.Dispose();
}
public ActionResult New()
{
var membershipTypes = _context.MembershipTypes.ToList();
var viewModel = new NewCustomerViewModel();
return View(viewModel);
}
public ViewResult CustomerGoesHere()
{
var customers = _context.Customers.Include(c => c.MembershipTypes).ToList();
return View(customers);
}
public ActionResult Details(int id)
{
var customer = _context.Customers.SingleOrDefault(c => c.Id == id);
if (customer == null)
return HttpNotFound();
return View(customer);
}
}
}
ありがとうございます。私はその部分を忘れていました。それは今働いている! – Andy