2012-01-07 11 views
0

私はEditorTemplateを作成しEditorTemplate。コードで</p> <p><img src="https://i.stack.imgur.com/FNOz8.png" alt="enter image description here"></p> <p>:MVC3

@model RentSite.Web.UI.Models.PhonesViewModel 

<div> 
@Html.TextBoxFor(m=>Model.Number) @Html.TextBoxFor(m => Model.From) @Html.TextBoxFor(m => Model.To) 
</div> 

、私はこのようにそれを使用しよう:

@model RentSite.Web.UI.Models.ContactsViewModel 

@{ 
    ViewBag.Title = "AddContact"; 
} 

<h2>AddContact</h2> 
@using (Html.BeginForm("AddContact","Contact",FormMethod.Post, new {enctype = "multipart/form-data"})) 
{  
    <input type="file" name="Image"/> 
    @Html.EditorFor(model=>model.Phoness) 
    <input type="submit" value="Add"/> 
} 

ContactsViewModelは次のようになります。

namespace RentSite.Web.UI.Models 
{ 
    public class ContactsViewModel 
    { 
     public string Name { get; set; } 
     public IEnumerable<PhonesViewModel> Phoness { get; set; } 
    } 
} 

しかし、私はページでエディタを見ることができません...なぜですか?

答えて

2

あなたのエディタテンプレートモデルは、PhonesViewModelタイプのものですが、model.Phoness(IEnumerable of PhoneViewModel)で呼び出すとします。お使いのエディタのテンプレートファイルで

、変更@model RentSite.Web.UI.Models.PhonesViewModel

@model IEnumerable<RentSite.Web.UI.Models.PhonesViewModel> 
+0

にそれは私が必要とまさにません。そして、最後に、それは動作しません。 – korovaisdead

+0

あなたの期待どおりの結果は? – Shyju

+0

このContactsViewModelから1つ以上の電話を追加できます。 – korovaisdead

関連する問題

 関連する問題