Question

I'm doing a code first ASP .NET MVC project.

In my view, I'm taking in the entity.

@model MyProject.Model.MyEntity

Within the view I am rendering a partial view, passing in the model.

@Html.Partial("_Edit", Model)

In this partial view I have defined the model as an object.

@model object

When I display the model's type I get what appears to be a GUID appended to it.

@{
    Type entityType = Model.GetType();
    string singularName = entityType.Name;
}

@{ ViewBag.Title = "Edit an existing " + singularName; }

This is what I see on screen:

Edit an existing MyEntity_CB3FF0C41867D7757E4AF90F10EE2F7ED5B407EFCB96592EC3FB0A06DCAB902B

Anyone know why and is there a way around it other than doing a SubString() on the underscore?

Was it helpful?

Solution

This issue is rooted in Entity Framework rather than MVC x.

I ran into the same problem and printed out the fully qualified name of my model ("SupportContactSecurity"):

System.Data.Entity.DynamicProxies.SupportContactSecuri_4C68726A6CC129D0001F286F1E38612D8DEC28F26CA3D3884B53BCDF810D8E6A 

DynamicProxies being the keyword there. Entity framework (by default) replaces your entities with these proxies so it can do change tracking at the context level (I think). If you want to turn this off, refer to this Stack Exchange question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top