I believe the problem here is that the compiler is choosing the wrong overload. If you look at the overloads of EditorFor, you see there are two that take two parameters:
public static MvcHtmlString EditorFor<TModel, TValue>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression,
Object additionalViewData
)
and
public static MvcHtmlString EditorFor<TModel, TValue>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression,
string templateName
)
You could try this:
@Html.EditorFor(model => Model,
Contoso.Core.QuestionRepositoryManager.GetQuestionView(Model) as string)
or you could do this:
@Html.EditorFor(model => Model,
Contoso.Core.QuestionRepositoryManager.GetQuestionView(Model), null)
There are also two constructors that take 3 arguments, but either of them, the second argument is always the template name, so by passing null it really doesn't matter which is chosen.
The problem may also be that GetQuestionView()
returns an object instead of a string, and that is why it's choosing the wrong constructor, making sure the return type of GetQuestionView()
is string may also fix it. Although I'm not sure why it works with Editor, since the same problem would exist there as the constructors are pretty analogous.