BoC
BoC copied to clipboard
Assembly Information Displayed in MVC4 Views
Using precompiled views and the ApplicationPartRegistry with RazorGenerator (from CodePlex) and MVC4, there is a string of the assembly information that is displayed when the view is rendered in the host. I don't see the string in an MVC3 project.
I am building the view DLLs in a separate project altogether. The text that is displayed invariably looks something like the following:
, MyProject.ViewDllName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=
It is just output as plain text in line, not rendered in a tag of any kind, and always right before the HTML of the view is rendered/output. There's nothing before the ,
at the start nor after the =
at the end
This is true of full ActionResults and views that are rendered via calls to RenderPartial. If I decompile the source of the view in the DLL, there does not seem to be any statements that would output this text.
Do you have any ideas as to what might be causing this text to be output?
Thanks in advance, MisterJames
Hi James,
I am facing the same issue. did you got the soultion for it.
Thanks Tony
Tony, unfortunately I haven't found a fix here, nor have I been able to locate where the text is actually coming from.
What I did to get around it is to create an on-doc ready handler in jQuery, used a global regex replace and removed the empty text node where the text is located. I have this in my _layout, and I call the javascript function whenever page loads or an Ajax operation completes.
Sorry if that isn't what you wanted to hear. If you would like I can post the code to strip out the text.
-j
Hi James,
i was able to resolve it.
you have to make changes to the below class, it work for me.
public class CompiledVirtualFile : VirtualFile { public CompiledVirtualFile(string virtualPath, Type compiledType): base(virtualPath) { CompiledType = compiledType; }
public Type CompiledType { get; set; }
/// <summary>
/// When overridden in a derived class, returns a read-only stream to the virtual resource.
/// </summary>
/// <returns>
/// A read-only stream to the virtual file.
/// </returns>
public override Stream Open()
{
// change code for CompiledType.AssemblyQualifiedName
return new MemoryStream(Encoding.ASCII.GetBytes("@inherits " + CompiledType.AssemblyQualifiedName.Substring(0,CompiledType.AssemblyQualifiedName.IndexOf(",")) + "\n@{base.Execute();}"));
}
}
Hey Tony, awesome to hear. Make sure you submit a pull request, eh?
The jQuery way was the path of least resistance for me, but this is a much better approach.
Cheers.