2017-12-08 6 views
0

MVC보기에서 모든 국가로 채워지는 국가 목록이 있습니다. 이것은 정상적으로 작동하고 사용자는 다른 국가를 선택합니다. & 확인이 표시됩니다. 해당 필드를 "Select Country"로 다시 변경하는 Javascript의 기능을 원합니다. 어떻게해야합니까?mvc 면도기 드롭 다운 목록 표시 기본값은 javascript

이 내 시야에

<div class="form-group"> 
    @Html.DropDownListFor(model => model.country, ViewBag.countrylist as SelectList, "Select Country", htmlAttributes: new { @id = "ddlcountry" }) 
</div> 

이 내가 다시 "국가 선택"쇼의 기본을 어떻게 내 자바 스크립트

$("#ddlcountry").val(44); //this works to set the country code to 44 
$("#ddlcountry").val("Select Country"); //this does not work to display "Select Country" like the default when you first load the page 

입니까? 감사 -

답변

0

귀하의 DropDownListFor() 방법은 jQuery로 해당 옵션이

$("#ddlcountry").val(''); 
+0

완벽 근무 사용할 선택하기 null

<option value="">Select Country</option> 

으로 '레이블 옵션을'생성됩니다! – e2fx