視圖模型
[Validator(typeof(ProdutoCategoriaValidator))]
public class ProdutoCategoriaViewModel
{
[HiddenInput(DisplayValue = false)]
public Guid ID { get; set; }
public IEnumerable<SelectListItem> Tipos { get; set; } // <<<<------- Is not showing in my view
[AdditionalMetadata("data-bind", "event: { change: function(data) { Link(data.Nome()); }}")]
public string Nome { get; set; }
[DataType(DataType.Url)]
[AdditionalMetadata("Prefixo", "Produtos/{tipo-de-produto}#")]
public string Link { get; set; }
public int? Ordem { get; set; }
public ProdutoCategoriaViewModel()
{
ID = Guid.NewGuid();
}
}
解決方案
IEnumerable的在我的視圖模型不與EditorForModel
視圖(_Formulario.cshtml)
@model ProdutoCategoriaViewModel
@using (Html.BeginForm(null, null, FormMethod.Post, new { id="form-produtocategoria", data_bind = "submit: salvar" }))
{
@Html.AntiForgeryToken()
<legend>@Html.MvcSiteMap().SiteMapTitle()</legend>
<fieldset>
@Html.ValidationSummary(false, "Verifique os erros abaixo:")
@Html.EditorForModel()
</fieldset>
<div class="buttons">
@Html.ActionLink("Cancelar", "Index")
<input type="submit" value="SALVAR" />
</div>
}
SelectListItem.cshtml
顯示10@model IEnumerable<SelectListItem>
@Html.DropDownListFor(m => m, Model)
<p>Test</p>
結果
完整映像:http://i.imgur.com/I7HxA.png
注
- 我試圖把屬性 「UIHint」,但仍顯示什麼!
問題
我在做什麼錯?
感謝您的解釋..我不會這樣做每個屬性,我會至少使用'UIHint'屬性。問題是,即使我添加了'UIHint',沒有任何反應! – ridermansb 2012-03-15 17:06:51
@Riderman de Sousa Barbosa,沒有任何反應,因爲正如我所說的,在默認的對象模板中,ASP.NET MVC不會遞歸到複雜的屬性。所以即使你在你的Tipos屬性上放置一個UIHint,它也會被忽略。您需要修改Brad Wilson顯示的默認Object.cshtml模板。 – 2012-03-15 17:12:09
我明白了。那麼我想避免這種情況,但我必須這樣做。謝謝您的幫助! – ridermansb 2012-03-15 17:15:44