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

Serialization error when trying to pass model object to child action using action method extension of Donutcache #63

Open
codeworm47 opened this issue Jun 24, 2017 · 1 comment

Comments

@codeworm47
Copy link

I'm passing a model object to Action method extension which recessives an extra parameter (excludeFromParentCache) to determine whether child action should be exclude from cache but I get this error

Type 'ECS.Infrastructure.ViewModels.ProductModel.ProductRichSnippetViewModel' with data contract name 'ProductRichSnippetViewModel:http://schemas.datacontract.org/2004/07/ECS.Infrastructure.ViewModels.ProductModel' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer'

here is my code in my view
@section RichSnippetJson{ @{ var productRichSnippet = new ECS.Infrastructure.ViewModels.ProductModel.ProductRichSnippetViewModel() { HasActiveSize = Model.Config != null && Model.Config.ProductSizes != null && Model.Config.ProductSizes.Any(p => p.Enabled), ImageUrl = Model.Config != null && Model.Config.ProductImages != null && Model.Config.ProductImages.Any() ? Model.Config.ProductImages.First() : "", ProductId = Model.ProductId, Url = Model.Config != null ? Url.ProductUrl(Model.ProductId, Model.Config.FaTitle) : ECS.Facade.FacadeInterface.Facade.GetAppConfigValue("Seo-Title-Site"), Availibility = (int)Model.Status, AlternateTitle = Model.Config != null ? Model.Config.EnTitle : "", Title = Model.Config != null ? Model.Config.FaTitle : "", BrandFaTitle = Model.Brand.FaTitle, Price = Model.Config != null && Model.Config.PriceInfo != null ? Model.Config.PriceInfo.Discount > 0 ? Model.Config.PriceInfo.DisplayPrice.Replace(",", "") : Model.Config.PriceInfo.PayableAmount.Replace(",", "") : "0", Description = Model.PageDescription }; } @Html.Action("GetRichSnippet", "Product", new { model = productRichSnippet },true) }

Do note that it's ok if I call default action method of mvc, so I think there must be a bug in Donutcache
2017-06-24_14-38-51

@mattbrailsford
Copy link

mattbrailsford commented Feb 21, 2020

Came across this issue myself. Assuming your model is something you know is serializable you can let the serializer know to expect it by adding the following to your web.config

<system.runtime.serialization>
    <dataContractSerializer>
        <declaredTypes>
            <add type="DevTrends.MvcDonutCaching.ActionSettings, DevTrends.MvcDonutCaching">
                <knownType type="ECS.Infrastructure.ViewModels.ProductModel.ProductRichSnippetViewModel, ECS.Infrastructure" />
            </add>
        </declaredTypes>
    </dataContractSerializer>
</system.runtime.serialization>

Where the knownType tag should be the fully qualified type name you want the serialize to know about.

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

No branches or pull requests

2 participants