0

まず、誤解を招くような質問の場合は申し訳ありませんが、質問の仕方がよくわからないので、例を挙げて説明します。

質問のより良いタイトルを提案できれば、喜んで変更します

私はこれらのモデルを持っています:

Public Class Tag
    Property TagID As Integer
    Property Name As String
    <Column(TypeName:="image")>
    Property Image As Byte()
    Property ImageMimeType As String
    Property CategoryID As Integer

    Overridable Property Category As Category
End Class

Public Class Category
    Property CategoryID As Integer
    Property Name As String

    Overridable Property Tags As ICollection(Of Tag)
End Class

次に、私のコントローラーは次のようになります。

Function EditCategories() As ActionResult
        Dim categories As IEnumerable(Of Category) = UW.CategoryRepository.GetAll
        Return View(categories)
End Function

今は私が物事を複雑にし始めるときです(少なくとも私にとっては)

私の見解は次のようなものです。

@modeltype IEnumerable(Of Category )
@Using Html.BeginForm("EditCategories", "Admin", FormMethod.Post,  New With {.enctype = "multipart/form-data"})
@Html.ValidationSummary(True)
    @<fieldset>
        <legend>Product</legend>
        @Html.EditorForModel()
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
End Using

EditorTemplateフォルダーにこのビューがあります

@ModelType ProcesadoraVizcaya.Category 
<div class="category-edit">
    <div>
        @Html.HiddenFor(Function(model) model.CategoryID)
        <div class="info-area">
            <div class="editor-label">
                @Html.LabelFor(Function(model) model.Name)
            </div>
            <div class="editor-field">
                @Html.EditorFor(Function(model) model.Name)
                @Html.ValidationMessageFor(Function(model) model.Name)
            </div>
        <hr />
        </div>
        <div class="tags-area">
                @Html.Partial("EditTags",Model.Tags )
        </div>
    </div>
</div>

ご覧のとおり、部分ビューを使用して各カテゴリ内のタグをレンダリングしています

だから私の部分的なビューはこのようなものです

@ModelType IEnumerable(Of ProcesadoraVizcaya.Tag)

@Html.EditorForModel()

再び私のEditorTemplateフォルダーに私はこのようなビューを持っています

@ModelType ProcesadoraVizcaya.Tag
<div>
    <div class="editor-label">
        @Html.LabelFor(Function(model) model.Name)
    </div>
    <div class="editor-field">
        @Html.EditorFor(Function(model) model.Name)
        @Html.ValidationMessageFor(Function(model) model.Name)
    </div>
    <div>
    </div>

</div>

この時点まで、すべてが順調に進み、すべてのカテゴリとタグをそれぞれ問題なくレンダリングして、遅延ロードが実行されます。

しかし、私が使用して投稿するとき:

<HttpPost()>
Function EditCategories(Categories As IEnumerable(Of Category)) As ActionResult
     Return View(Categories)
End Function

私はこれを手に入れます:

ここに画像の説明を入力してください

ご覧のとおり、タグは何もありません。

だから私の質問はこのようなものですどのように私はそれらのタグをサーバーに戻すのですか?

(私にはそれを行う他の方法がありますが、このアプローチを使用してそれを行うことが可能かどうか知りたいです)

(C#で答えがある場合は、それから作業することを知らせてください)

thxs!

4

1 に答える 1

4

ご覧のとおり、部分ビューを使用して各カテゴリ内のタグをレンダリングしています

それはあなたの問題だ。エディターテンプレートを使用する必要があります。

<div class="tags-area">
    @Html.EditorFor(Function(model) model.Tags)
</div>

次に、対応する~/Views/Shared/EditorTemplates/Tag.vbhtmlテンプレートが必要です。EditTags.vbhtmlパーシャルは必要ありません。

于 2013-01-27T13:40:33.880 に答える