覆盖ASP.NET MVC 3 RC中的默认EditorFor模板选择

Alx*_*ndr 7 asp.net-mvc templates editorfor

我正在创建一个MVC应用程序,它目前使用EditorFor来生成很多视图.整个视图基本上只是一个EditorForModel,它运行得很好.但是,我遇到了一个小问题,我似乎无法找到解决方案,并且重要的是它以我需要的方式工作,那就是在尝试渲染EditorFor一个接口时.绑定和类似的一切都得到了处理,但问题是EditorFor看到它是一个接口,默认为"对象"模板.我需要它来查看界面,看看它是否能找到具有该名称的模板,如果它不能,我需要它通过所有存在的接口来查看它是否与它们中的任何一个匹配.要更简单地解释一下这个例子:

接口:

public interface IAppProvider
{
    string Name { get; set; }
}

public interface IAppMusicProvider : IAppProvider
{
    int GetPlaylistCount();
} // Yeah, I know, this interface is not smart, but it's only for show.
Run Code Online (Sandbox Code Playgroud)

如果我现在用model ="IAppMusicProvider"创建一个View并运行Html.EditorForModel(),我需要它来找到"〜Views\Shared\EditorTemplates\IAppProvider.cshtml"-template.有什么简单的方法可以达到这个目的吗?

Joh*_*ell 1

您尝试过使用该[TemplateHint]属性吗?