2014-08-29 75 views
0

在我的html,我有以下的標記空白值,而不是價值

<div class="col-md-8"> 
       @*@Html.DropDownList("templateTypes", (IEnumerable<SelectListItem>)ViewBag.TemplateTypes, new { @class = "form-control", ng_model = "currentTemplate.tmplType" })*@ 
       <select class="form-control" name="templateTypes" id="templateTypes" 
         ng-model="currentTemplate.tmplType" 
         ng-options="t.value as t.text for t in templateTypes"></select> 
      </div> 

的tmplType在模型字節。值和文本是字符串。當我查看我的表單時,選擇變爲空白。如果我選擇一個不同的值(只有2個選項),我可以看到這個值正確地進入數據庫。但是,在重新加載表單後,select選項仍顯示爲空白。這裏可能是什麼問題?

+0

重裝後哪個值有你的currentTemplate.tmplType? – 2014-08-29 20:38:52

+0

是'currentTemplate.tmplType == t.value'?不知道我是否正確理解你,當'tmplType是字節'和'值和文本是字符串'時,你必須解析其中的一個。 – nilsK 2014-08-29 21:32:14

+0

在谷歌Chrome開發人員工具,我看到以下內容: $ scope.currentTemplate.tmplType $ scope.templateTypes [對象選擇:真正的文字: 「通過」 值: 「1」 所以,tmplType爲1,值是「1」。我不知道爲什麼它下拉顯示空白是有區別的 – Naomi 2014-08-29 21:56:58

回答

0

我解決了這個問題。我所要做的只是從評論代碼改爲字符串

// public TemplateTypes TmplType {get;組; } public string TmplType {get;組; }

現在工作很好。我不需要做其他任何事情,轉換會自動從字符串視圖模型轉換爲字節。