所以我有了它使用下面的模板下拉列表是從同一個模板生成不同
@using DigitalDjPool.Website.Domain.Profiles
@model DigitalDJPool.Website.UI.Models.ProfileWizard.UserDJTypeModel
<div class="row no-margin">
<div class="input-field col m4 s12"><h5>What type of DJ are you?</h5>
</div>
@Html.HiddenFor(m => m.UserMemberTypeId)
<div class="input-field col m4 s12">
@Html.DropDownListFor(m => m.SelectedMemberType, ((IEnumerable<MemberType>)Model.MemberTypesList)
.Select(t => new SelectListItem { Value = t.Id.ToString(), Text = t.Name, Selected = t.Id.ToString().CompareTo(Model.SelectedMemberType) == 0 }), new { @class = "editprofile-info-ddl" })
</div>
<div class="input-field col m4 s12">
@Html.TextBoxFor(m => m.MemberTypeInfo)
@Html.ValidationMessageFor(m=> m.MemberTypeInfo)
</div>
</div>
<div class="row no-margin">
<div class="input-field col m4 s12"><h5> What is your typical audience size? </h5></div>
<div class="input-field col m4 s12">
@Html.DropDownListFor(m => m.AudienceSize, new List<string> {"1-50", "50-499", "500+"}.Select(t => new SelectListItem {Value = t, Text = t, Selected = t == Model.AudienceSize}))
</div>
</div>
,當我最初創建的頁面的下拉列表出來的權利一些奇怪的原因DJTypeModel列表的類ProfileViewModel 但是當我使用ajax調用將另一個UserDjTypeModel添加到頁面時,我收到的html腳本將螺絲鎖定在下拉列表中。我收到的代碼與chrome視圖源代碼頁中的代碼相同,但是當我檢查元素時,頁面加載期間創建的代碼會有另一個標籤。我已經檢查過,沒有運行JSScript。該folloing的代碼所示在源頁面,並在HTML通過AJAX返回
<div class="row no-margin UserDjTypeModelObj">
<div class="input-field col m4 s12"><h5>What type of DJ are you?</h5>
</div>
<input id="UserDJTypeModel_0__UserMemberTypeId" name="UserDJTypeModel[0].UserMemberTypeId" type="hidden" value="2ad4c348-0120-4eeb-b031-a5b0008d0d43" />
<div class="input-field col m4 s12">
<select class="editprofile-info-ddl" id="UserDJTypeModel_0__SelectedMemberType" name="UserDJTypeModel[0].SelectedMemberType"><option value="f4579c21-8509-49df-9329-00fc33bd3344">College Radio</option>
<option selected="selected" value="8f670bf6-1a95-4c30-abac-2acac6fd3e05">FM Radio</option>
<option value="b9b14aca-81d2-49a1-9393-3c2e6552ff71">Mobile DJ</option>
<option value="d2744e05-8f19-4c80-915c-60f7582792d0">Tour DJ</option>
<option value="c7aa4e2a-0b77-4ce1-af51-7683e50c3b8f">Internet Radio</option>
<option value="8e4e882a-c650-4841-beb7-c18105b929ad">Satellite Radio</option>
<option value="561dcbec-e6d6-4f28-ae64-c50be123e64e">Bedroom DJ</option>
</select>
</div>
<div class="input-field col m4 s12">
<input id="UserDJTypeModel_0__MemberTypeInfo" name="UserDJTypeModel[0].MemberTypeInfo" type="text" value="98.7" />
<span class="field-validation-valid" data-valmsg-for="UserDJTypeModel[0].MemberTypeInfo" data-valmsg-replace="true"></span>
</div>
</div>
<div class="row no-margin">
<div class="input-field col m4 s12"><h5> What is your typical audience size? </h5></div>
<div class="input-field col m4 s12">
<select id="UserDJTypeModel_0__AudienceSize" name="UserDJTypeModel[0].AudienceSize"><option value="1-50">1-50</option>
<option value="50-499">50-499</option>
<option selected="selected" value="500+">500+</option>
</select>
</div>
這是返回的對象怎麼弄出來 ,你可以看到兩個下拉列表失敗雖然html代碼有顯示
要澄清,您是否從ajax調用或html代碼返回模型? –
Im將模型的局部視圖(如html)返回給ajax,它將html插入到dom中 –
ajax調用之前,頁面中已經存在局部視圖還是已經加載了?編輯:我的意思是你加載它兩次? –