문제

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 &lt;. 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 %>";

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top