Do the following then, in your class Carta
modify, so that when the data is received by the user screen it assigns in the array de bytes
automatically the values and when the ORM
assign the value to the array de bytes
it generates the information in text to be shown in View
:
Class:
public class Carta
{
public virtual int Id { get; set; }
private byte[] _descricao;
public virtual byte[] Descricao
{
get
{
return _descricao;
}
set
{
_descricao = value;
_descricaoString =
System.Text.Encoding.UTF8.GetString(value);
}
}
private String _descricaoString;
public string DescricaoString
{
get
{
return _descricaoString;
}
set
{
_descricaoString = value;
Descricao =
System.Text.Encoding.UTF8.GetBytes(value);
}
}
}
manages the View
with these changes that will result in:
View:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Carta</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.DescricaoString)
<div class="col-md-10">
@Html.EditorFor(model => model.DescricaoString)
@Html.ValidationMessageFor(model => model.DescricaoString, "")
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
with these modifications the data is already ready for View
and any attempt to change the data is converted to the format of array de bytes
, analyzing this if the whole mapping is correct and the field DescricaoString
has to be ignored in its model, so that the ORM
do not try to update this field which is only even a way to show and retrieve information:
Modifications to the Mapping of this class by adding:
map.IgnoreProperty(p => p.DescricaoString);
References:
You can create an attribute
string
inModel
and already send the converted data to theView
, and when post, convert again tobyte
.– Ricardo Pontual
Why are you doing this? You have some obligation!
– novic
Yes, I am trying to use the company standard, but the material I have has no example of how to do it @Virgilionovic
– Eluander J. F. Lopes
You save with ORM?
– novic
I use Nhibernate, if I’m not mistaken you mean a right ORM? @Virgilionovic
– Eluander J. F. Lopes
Worked?.....
– novic
Not yet, I get the idea but you’re having trouble putting this in my class. Because it does not let me define the "_Description" without the virtual one and if I put it virtual it says that the "_Description" is not valid for the kk item.. I’m trying to figure out a way to make it work.. @Virgilionovic
– Eluander J. F. Lopes
there’s something wrong because
_descricao
does not need this modifier!– novic