skliz4rel
skliz4rel

Reputation: 198

Using AntiXss to encode html Attribute in mvc

I am trying to pass an id from my controller to my view and encode this value in the Antixss function but I am getting an error.

This is my code

input  type="hidden" name="Moderator" value="@AntiXss.HtmlAttributeEncode(ViewBag.ModeratorID)" readOnly="readonly" />

The error message is

The best overloaded method match for 'Microsoft.Security.Application.AntiXss.HtmlAttributeEncode(string)' has some invalid arguments

Upvotes: 1

Views: 940

Answers (1)

Brandon
Brandon

Reputation: 69973

ViewBag is a dynamic type, so call ToString() on ModeratorID.

@AntiXss.HtmlAttributeEncode(ViewBag.ModeratorID.ToString())

Upvotes: 2

Related Questions