开发者

Html helpers no longer able to infer type arguments

Full error text:

The type arguments for method 'System.Web.Mvc.Html.DisplayExtensions.DisplayFor<TModel,TValue>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TValue>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

It just recently started happening, though I don't believe I made any changes that would affect this functionality. It throws VS intellisense error, but the pages function开发者_开发技巧 just fine.

Html helpers that are not "For" helpers work just fine, it's only the ones that contain these expressions.

The offending markup(1 example of 100s):

 <%: Html.DisplayFor(model => model.PortfolioName) %>    

Page Directive:

<%@ Page Language="C#" Inherits="ViewPage<My.Namespace.PortfolioViewModel>" %>

View Model:

namespace My.Namespace
{
    public class PortfolioViewModel
    {
        [Required(ErrorMessage = " ")]
        [DataType(DataType.Text)]
        [DisplayName("Portfolio Name:* ")]
        public string PortfolioName { get; set; }
     }
}


It sounds stupid, I know, but have you tried closing and reopening VS?


When I ran into this problem previously, it was after we upgraded MVC versions and the web.config references were not properly updated. This meant that the views were relying on references to older versions of the HTML extension methods.

Look at your references and ensure that the version is correct.


The Html.DisplayFor method will find a suitable display template for the specified type. The exception seems a little odd but it might indicate that no display template have been registered for the string type.

You might want to try Html.LabelFor for testing purposes. Do you have a special display template for strings?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜