Не уверен, что здесь происходит ...
Мои методы контроллера выглядят так:
[HttpGet]
public ActionResult RequestAppointment()
{
var appointmentRequest = new AppointmentRequest
{
Stylists = _repository.Stylists // <-- Debugging shows that Stylists IS being populated here
};
return View(appointmentRequest);
}
[HttpPost]
public ActionResult RequestAppointment(AppointmentRequest appointmentRequest)
{
if(ModelState.IsValid)
{
// Process...
return RedirectToAction("Confirmation");
}
return View(appointmentRequest);
}
Форма выглядит так:
@model MyDomain.Models.AppointmentRequest
@using(Html.BeginForm("RequestAppointment", "Appointment" FormMethod.Post))
{
// This following line throws the exception:
@Html.DropDownListFor(x => x.Stylist,
Model.Stylists.Select(x => new SelectListItem{ Text = x.Name, Value = x.Name })))
<input type="submit" value="Make Request" />
}
выпадающий список заполняется формой с правильным текстом и значениями.Но когда форма отправлена, возникает исключение.Что происходит?
Трассировка стека:
[ArgumentNullException: Value cannot be null.
Parameter name: source]
System.Linq.Enumerable.Select(IEnumerable`1 source, Func`2 selector) +6396316
ASP._Page_Views_Appointment_RequestAppointment_cshtml.Execute() in c:\Projects\OasisSalon\OasisSalon.Mvc\Views\Appointment\RequestAppointment.cshtml:9
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
System.Web.WebPages.StartPage.ExecutePageHierarchy() +143
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +157
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +384
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +825460
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825488
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375