jeudi 19 mai 2016

using reflection and html helper wont submit values [duplicate]

This question already has an answer here:

what i am doing is simple. based on an object show only the properties i want to. Now having an instantiated object with values. the problem i encountered were a few. if i use an EditorFor to give it the value it will throw the following error.
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
I tried to fix it but anything i tried wasn't working, the only thing i didn't try is a custom helper. so i decided to see if i can use Editor and this time it doesn't get the values.
I decided to use TextBox this time the values are loaded but when i submit the model view object is null.
Below is the code i use in the view the only change is in the HtmHelper.Editor/Textbox/EditorFor

@foreach (var item in Model.AttributesList) //List of PropertyInfo
    {
        <div class="form-group">
            @Html.Label(item.Name, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.Editor("Test", item.GetValue(Model.object))
            </div>
        </div>
    }

For the editor part i replaced it as follow

@Html.Editor("Test", item.GetValue(Model.entityType))
@Html.TextBox("Test", item.GetValue(Model.entityType).ToString())
@Html.EditorFor(m => item.GetValue(Model.entityType).ToString())
@Html.EditorFor(m => item.GetValue(m.entityType))





Aucun commentaire:

Enregistrer un commentaire