0

Im using signaturepad from Nuget, everything is fine with the exception of trying to recreate signatures from the byte array stored on the server.

My Model has

public byte[] MySignature { get; set; }

and in my index view I have this to try and display the signature, but all I ever get is invalid urls

<td>
        @{
            if (item.MySignature != null)
            {
                <img src="@string.Format("data:image/jpeg;base64,{0}", Convert.ToBase64String(item.MySignature));" />
            }
        }
</td>

Am I missing something plainly obvious?

  • Not quite sure if it's your problem, but the semicolon `;` is not necessary at the end. – juunas Mar 02 '17 at 21:13
  • You sir, are a legend. Originally I put it altogether in multiple lines and the ; was just left over from a copy paste. Worked like a charm. If you wanna add an answer I'll mark it. – Kevin Knapp Mar 02 '17 at 22:11

1 Answers1

1

Turns out my guess was right :)

The semicolon at the end of the src attribute value was superfluous:

<img src="@string.Format("data:image/jpeg;base64,{0}", Convert.ToBase64String(item.MySignature));" />

It must be:

<img src="@string.Format("data:image/jpeg;base64,{0}", Convert.ToBase64String(item.MySignature))" />

The reason is that the first one includes the semicolon in the base-64 string, which makes it invalid.

juunas
  • 54,244
  • 13
  • 113
  • 149