I have some troubles with a text box input control value on an ascx page. It's value is somehow always html encoded, and I don't know how it can be disabled.
For example when the value contains a <
character it is always converted to <
. The strange thing is, it only happens on fields like Name.Lastname
(which have a child property). My first thought was it could be caused by the Html extension method
Html.TextBoxFor(m => m.Name.LastName, new { maxlength = "100" })
but this is not the case, because when I use the html input directly, it's value is still encoded:
<input id="Name_LastName" maxlength="100"
name="Name.LastName"
type="text" value="<%= Model.Name.LastName %>" />
Does somebody know how the html encoding of text box values for fields like Name.LastName
(with a child property) can be disabled?
After more research I found out that it was caused by a javascript function which variables were initialized using the <%:
, and this function was used to initialize the text boxes. So in the end it had nothing to do with child properties. I changed the <%:
with <%=
in the javascript part:
var lastName = "<%: Model.Name.LastName %>";
in
var lastName = "<%= Model.Name.LastName %>";