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();
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>
</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>
</div>
What I have tried:
We can fix this issue by specifying the actual location in the return statement.