开发者

ASP.NET MVC "The call is ambiguous" Error (System.IO.TextWriter.Write)

I am creating a dynamic CSS file in ASP.NET MVC2, and I'm now encountering an exception. Everything was working fine, but all of a sudden I'm getting this error message for 2 variables:

The call is ambiguous between the following methods or properties: 'System.IO.TextWriter.Write(string, params object[])' and 'System.IO.TextWriter.Write(char[])'

开发者_StackOverflow社区

An example of the code is:

#pageMaster .CCResultsText2 { 
    font-size: <%= ViewData.Model.FontSize %>; 
    color: <%= ViewData.Model.FontColor %>; 
}

This error gets resolved, however, when I replace <%= ViewData.Model.FontColor %> with <% Response.Write(ViewData.Model.FontColor); %>

It seems that there seems to be some kind of issue differentiating the two different forms of the System.IO.TextWriter.Write method, but I'm not exactly sure what I can do besides write out the Response.Write method.


Try to cast your model member to a specific type like:

#pageMaster .CCResultsText2 { 
    font-size: <%= (int)ViewData.Model.FontSize %>; 
    color: <%= (string)ViewData.Model.FontColor %>; 
}

The types are just my guess.. cast it to proper types of course ;)


My problem was that the values in the view were being set in a base class and I forgot to have the new controller inherit from the base controller.

The resulting null values returned by the ViewBag created the ambiguity.

FYI adding the type cast as described in the other answer will make the error go away but it does not solve the underlying issue where the values were not being set correctly in the controller.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜