Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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[])'

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.

like image 615
cfitzarl Avatar asked Aug 11 '10 19:08

cfitzarl


2 Answers

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 ;)

like image 169
Łukasz W. Avatar answered Oct 10 '22 14:10

Łukasz W.


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.

like image 1
Roland Schaer Avatar answered Oct 10 '22 16:10

Roland Schaer