Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DropDownListFor binding
Message
 
 
General information
Forum:
ASP.NET
Category:
MVC
Environment versions
Environment:
C# 5.0
Miscellaneous
Thread ID:
01562476
Message ID:
01562651
Views:
22
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform