Элемент модели, переданный в словарь, имеет тип, но этот словарь требует модели «Система типа». Collections.generic.IenuC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Элемент модели, переданный в словарь, имеет тип, но этот словарь требует модели «Система типа». Collections.generic.Ienu

Сообщение Anonymous »

Вот что я пытаюсь сделать. Я не понимаю, почему он ожидает перечисляемый список.public ActionResult ShowAddresses(List ReturnAddresses)
{
ShowAddressViewModel viewModel = new ShowAddressViewModel() { Addresses = ReturnAddresses, Message = "New" };
return PartialView("_ShowAddr", viewModel);
}
< /code>
функциональныйpublic class ShowAddressViewModel
{
public List Addresses { get; set; }
public string Message { get; set; }
}
< /code>
функциональный@model PeopleSoftControlsPOC.Models.ShowAddressViewModel





@{int i = 0;}
@{PeopleSoftControlsPOC.Models.ShowAddressViewModel AddrModel = Model;}
@foreach (var item in AddrModel.Addresses)
{

@(AddrModel.Addresses.Address1)
@(AddrModel.Addresses.Address2)
@(AddrModel.Addresses.City)
@(AddrModel.Addresses.State)
@(AddrModel.Addresses.Zip)

@(i++)
}



< /code>
edit < /p>
вызов из другого частичного представления Javascript < /p>
$.ajax( url,
{
data : { ReturnAddresses : InboundAddresses },
type : 'POST',
cache : false,
crossDomain : true,
success : function (data)
{
// Populate the form values
// Start Dialog Code
$myWindow = jQuery('#myDiv');
// instantiate the dialog
$myWindow.html(data);
$myWindow.dialog(
{
title : 'Select an address',
modal : true,
width : 'auto'
});
$myWindow.show();
$myWindow.dialog("open");
// End Dialog Code

$('#AddressTable').on('click', 'tr', function ()
{
alert('You clicked row ' + ($(this).index()));
});
addAddress(Addresses, Message)
},
error : function (jqXHR, textStatus, errorThrown)
{
$('#Message').val('Kaboom!!! (The call blew up...#thatsucks)');
alert( 'The Dialog Box call failed...Sorry :(' );
}
});
}
< /code>

Ошибка сервера в приложении ' /pspoc'.The model item passed into the dictionary is of type 'PeopleSoftControlsPOC.Models.ShowAddressViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[PeopleSoftControlsPOC.Models.ShowAddressViewModel]'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'PeopleSoftControlsPOC.Models.ShowAddressViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[PeopleSoftControlsPOC.Models.ShowAddressViewModel]'.
< /code>

ошибка источника: < /p>
< /blockquote>
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
< /code>
Stack Trace: < /h6>
[InvalidOperationException: The model item passed into the dictionary is of type 'PeopleSoftControlsPOC.Models.ShowAddressViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[PeopleSoftControlsPOC.Models.ShowAddressViewModel]'.]
System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +383
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +625
System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData) +74
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +138
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378
System.Web.Mvc.c__DisplayClass1c.b__19() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +727120
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +727076
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +334
System.Web.Mvc.c__DisplayClassb.b__5() +62
System.Web.Mvc.Async.c__DisplayClass1.b__0() +15
System.Web.Mvc.c__DisplayClasse.b__d() +52
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288quest>b__d() +52
< /code>

Информация о версии: Microsoft .net Framework Версия: 4.0.30319; Версия ASP.NET: 4.0.30319.18044


Подробнее здесь: https://stackoverflow.com/questions/192 ... ary-requir
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»