Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentException occured while view rendering #15

Open
petrvmakarov opened this issue Apr 4, 2014 · 2 comments
Open

ArgumentException occured while view rendering #15

petrvmakarov opened this issue Apr 4, 2014 · 2 comments
Labels

Comments

@petrvmakarov
Copy link

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.

@petrvmakarov
Copy link
Author

workaround found: "@model object" as the first line in _Layout.cshtml

@panesofglass
Copy link
Member

Interesting. Thanks for posting the work-around!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants