Issue: Line: 33
The model item passed into the dictionary is of type 'Public.Web.Models.PaymentViewModel', but this dictionary requires a model item of type 'Public.Web.Models.BadCheckSearchViewModel'. 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 'Public.Web.Models.PaymentViewModel', but this dictionary requires a model item of type 'Public.Web.Models.BadCheckSearchViewModel'. Source Error: Line 31: Line 32: Payment for Line 33: @Html.Partial("_BadCheckSubmittedForPayment", ((Public.Web.Models.BadCheckSearchViewModel)(Model.BadCheckSubmittedForPayment))) Line 34: Line 35: @Html.LabelFor(model => model.Payment.ServiceChargeDisplay, new { @class = "label-inline" })
Server: Windows Server 2003R2 32bit
Index.cshtml
@using BootstrapSupport
@model Public.Web.Models.PaymentViewModel
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_BootstrapLayout.basic.cshtml";
}
<style type="text/css">
.form-condensed .control-group {
margin-top: 0;
margin-bottom: 5px;
}
.label-inline {
display: inline;
}
</style>
@Html.Partial("_ReturnToSearch")
@using (Html.BeginForm("SubmitPayment", "Payment", FormMethod.Post, new { @class = "form-horizontal form-condensed", id = "paymentform" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="container">
<div class="row">
<div class="span4">
@*@using (Html.BeginForm("UpdatePayment", "Payment", FormMethod.Post, new { @class = "form-horizontal form-condensed", id = "partialpaymentform" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
*@<div class="well">
<fieldset>
<legend>Payment for</legend>
@Html.Partial("_BadCheckSubmittedForPayment", (Public.Web.Models.BadCheckSearchViewModel)Model.BadCheckSubmittedForPayment)
Controller:
public ActionResult Index()
{
var paymentViewModel = new PaymentViewModel();
try
{
if (Session["SubmittedBadCheckForPayment"] != null)
{
BadCheckSearchViewModel submittedForPayment = Session["SubmittedBadCheckForPayment"] as BadCheckSearchViewModel;
if (submittedForPayment != null)
{
var uri = System.Web.Configuration.WebConfigurationManager.AppSettings["BadCheckServiceUrl"];
_ctx = new Public.Web.BadChecks.CmsPublicEntities(new Uri(uri));
paymentViewModel.BadCheckSubmittedForPayment = submittedForPayment;
//.........
}
}
}
catch (Exception ex)
{
//....
}
return View(paymentViewModel);
}
Model:
public class PaymentViewModel
{
private BadCheckSearchViewModel _badCheckSubmittedForPayment;
public BadCheckSearchViewModel BadCheckSubmittedForPayment
{
get
{
return _badCheckSubmittedForPayment;
}
set
{
_badCheckSubmittedForPayment = value;
}
}
}
Model: BadChecks
public class BadCheckSearchViewModel
{
private Double? originalAmount;
public string ApplicationCode { get; set; }
public decimal CaseId { get; set; }
public decimal PartySequence { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string FullName { get; set; }
- I have seen other posts where they say to make the @model declaration IEnumerable/List. I do not think this applies because I am not expecting it to enumerate through a list or I don't think I am.
- This works on various other machines. The ones I know off the top of my head are: Windows Server 2012, Windows 7.
- MVC 3, ASP.net Web Pages, .Net 2 and .Net 4 Client/Extended is installed
- Experience Level with MVC: Entry-Junior
- By the time the error has occured, we have accessed the site, searched. When selecting an entry to access this view, it errors.
- I would love to solve this problem by telling them to upgrade to Windows Server 2012, but I can't.
- This is customer site
- Less than 1gb of space on both drives.
Actual Issue:
paymentViewModel.BadCheckSubmittedForPayment = submittedForPayment;
paymentViewModel.Payment.ShowEmailIfConfiguredToSendEmail = _cmsPublicSettings.ShowEmailAddressOnPaymentForm; //Object Reference Error Here on this property.
@Html.Partial("_ReturnToSearch")
? – user3559349@Html.Partial("_BadCheckSubmittedForPayment", Model.BadCheckSubmittedForPayment)
, but I suspect that propertyBadCheckSubmittedForPayment
is null which means that you actually passingPaymentViewModel
to the partial (notBadCheckSearchViewModel
) – user3559349BadCheckSubmittedForPayment
isnull
(debug you code) You should initialize propertyBadCheckSubmittedForPayment
to a new instance ofBadCheckSearchViewModel
in a parameterless constructor forPaymentViewModel
– user3559349