Skip to content

ArgumentException occured while view rendering #15

Open
@petrvmakarov

Description

@petrvmakarov

Models

public class CustomerDetials
{
public string FullName { get; set; }
}

public class ServiceDetials
{
public string Name { get; set; }
}

Controllers

//http://localhost/customer/details
public class CustomerController : ApiController
{
[HttpGet]
public CustomerDetials Detials()
{
return new CustomerDetials { FullName = "Full Name" };
}
}

//http://localhost/service/details
public class ServiceController : ApiController
{
[HttpGet]
public ServiceDetials Detials()
{
return new ServiceDetials{ Name = "The service" };
}
}

Views


CustomerDetials.cshtml:

@model Models.CustomerDetials
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}

Customer name is @Model.FullName


ServiceDetials.cshtml:

@model Models.ServiceDetials
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}

Service name is @Model.Name

Steps to reproduce:
1)browse to http://localhost/customer/details
1.1) Succefully
2)browse to http://localhost/service/details
2.1) Failed to render

ArgumentException occured in RazorViewParser::GetParsedView in return _templateService.Run(view.ViewName, view.Model, null);

Object of type 'Models.ServiceDetials' cannot be converted to type 'Models.CustomerDetials'

It looks like ceche issue. But I found a workaround if I remove Layout = "~/Views/Shared/_Layout.cshtml"; line from every view I would not get that issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions