Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DropDownListFor binding
Message
 
 
À
15/01/2013 11:24:36
Information générale
Forum:
ASP.NET
Catégorie:
MVC
Versions des environnements
Environment:
C# 5.0
Divers
Thread ID:
01562476
Message ID:
01562651
Vues:
20
>>The problem now is that I can not directly use setFormControls as the above because my form is much more complex and I don't even expose Ids for controls.
>
>Don't see how the jscript can modify items if it has not way of identifying them - but javascript is *not* my specialist subject.
>Why not give them Id's ?
>
Sorry for drifting the thread in different direction. The reason I can not easily give id is that EditorFor is not a regular editor for, it is
<div class="editor-label">
    @Html.Label((ViewData.ModelMetadata.DisplayName??ViewData.ModelMetadata.PropertyName),
        new Dictionary<string, object>
            {                
                { "for", ViewData.ModelMetadata.PropertyName }
            })
</div>

<div class="editor-field">
   @if (ViewData.ModelMetadata.ModelType.IsNumeric())
   {
    @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { type = "number", @class = "numericOnly"  })      
   }
    else
    {
     @Html.TextBox("", (object)Model,
        new Dictionary<string, object>
            {
                { "id", ViewData.ModelMetadata.PropertyName },
                { "name", ViewData.ModelMetadata.PropertyName },
                { "class", "text-box single-line"},
                { "data-bind", "value: " + ViewData.ModelMetadata.PropertyName },
            })
    }
   
     @Html.ValidationMessage(ViewData.ModelMetadata.PropertyName,
        new Dictionary<string, object>
            {
                { "data-valmsg-for", ViewData.ModelMetadata.PropertyName }
            })
</div>
And also there are many elements in that view so mapping each manually with returned data is a bit complex. I wish there can be some simple way of automatically setting Model = returned JSON data so I don't have to manually use setFormsControls.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform