Click here to Skip to main content
15,562,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Below is my scenario.

I am working in mvc 5 project. In this project, we have same file names in two different location (for two different features).

WebProject\Controllers\OrdersTrackingController.cs - This one using ViewModelA
WebProject\Views\OrdersTracking\ShowDetail.ascx

WebProject\Areas\PatientChart\Controllers\OrdersTrackingController.cs - This one using ViewModelB
WebProject\Areas\PatientChart\Views\OrdersTracking\ShowDetail.ascx

In ShowDetail() method, in each controller returns the partial view with respective model.

This method will be called when ShowDetail button is clicked. This is working fine also.

Sometimes in production server, we are getting an issue as follows,

"The model item passed into the dictionary is of type 'WebProject.Areas.PatientChart.Models.ViewModelA', but this dictionary requires a model item of type 'WebProject.Models.ViewModelB'."


The above issue is not always happening. We are not able to reproduce the issue in local. This issue is happened occasionally in production server.

Any idea why it is try to render another view (different model).


Below is the sample code:

In WebProject\Areas\PatientChart\Controllers\OrdersTrackingController.cs,

public ActionResult OrderDetails(int id)
{
	ViewModelB model = new ViewModelB();            
	
	// Here we have logic to fill the view model
	
	return PartialView(model);
}

In WebProject\Areas\PatientChart\Views\OrdersTracking\ShowDetail.ascx,

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Panther.Web.Areas.PatientChart.Models.ViewModelB>" %>
<div>
<!-- here we have display logic -->
</div>


In WebProject\Controllers\OrdersTrackingController.cs, 

public ActionResult OrderDetails(int id)
{
	ViewModelA model = new ViewModelA();
	
	// Here we have logic to fill the view model
	
	return PartialView(model);
}

In WebProject\Views\OrdersTracking\ShowDetail.ascx,

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ViewModelA>" %>
<div>
<!-- here we have display logic -->
</div>


What I have tried:

We can fix this issue by specifying the actual location in the return statement.
Posted
Updated 7-Jun-17 23:46pm
v3
Comments
John C Rayan 8-Jun-17 4:18am    
We can help out if you could show us the code from both the controller and views.
Arunachalam Muthukumar 8-Jun-17 4:49am    
I've updated the code sample. The issue is not always happening. Just I am trying to find the actual root cause.
F-ES Sitecore 8-Jun-17 4:43am    
Search the code for anywhere that returns that view or uses ViewModelA as there must be some condition somewhere where that model is passed to that view.
Arunachalam Muthukumar 8-Jun-17 4:49am    
Ok. I ll search.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900