MvcScaffold Does Not Create Corresponding Related Dropdowns

MvcScaffold Version: 0.9.7

Ok, so MvcScaffold generates this code for me in a partial view of _CreateOrEdit.cshtml:

<div class="editor-field">
    @Html.DropDownListFor(model => model.LocationId, ((IEnumerable<JobSite.Models.Location>)ViewBag.PossibleLocations).Select(option => new SelectListItem {
        Text = Html.DisplayTextFor(_ => option).ToString(), 
        Value = option.LocationId.ToString(),
        Selected = (Model != null) && (option.LocationId == Model.LocationId)
    }), "Choose...")
    @Html.ValidationMessageFor(model => model.LocationId)
</div>

In this case, the following HTML is created:

<select data-val="true" data-val-number="The field LocationId must be a number." data-val-required="The LocationId field is required." id="LocationId" name="LocationId"><option value="">Choose...</option>
     <option value="1">1</option>
     <option value="2">2</option>
</select>

As you will see, the “text” of quenching is displayed in the same way as the “value”.

Obviously, every time I can re-insert this code manually by doing:

Text = Html.DisplayTextFor(_ => option.LocationName).ToString(), 

... but I would like to fix the problem to avoid this.

Can anyone suggest any recommendations?

Thanks Paul

+3
source share
1 answer

, , MvcScaffolding , . , , , , , "text". , , "", "" .. , text. , :

static string[] displayPropertyNames = new[] { "Name", "Title", "LastName", "Surname", "Subject", "Count" };

, , , . , / , , .

, , DisplayColumn , . :

[DisplayColumn("LocationName")] public partial class DropDownBoundType {}

, , MvcScaffolding . , , , . , , , , , , , , .

, 9.7, , 9.8. , , . , .

+1

All Articles