开发者

partial view inside partial view --- conditional

I am porting 开发者_开发问答a web forms application to MVC3

I have a partial view inside a partial view and the inner partial view is displayed on the basis of content from the model of the parent view.

The parent partial view has this model

@ModelType List(Of Integer)

and then these lines for adding multiple instances of a partial view in the same page.

<div style="width: 25%; vertical-align: bottom; float: left; clear: left">
    @Html.Partial("ArtBlock")
</div>
<div style="width: 25%; vertical-align: bottom; float: left; clear: left">
    @Html.Partial("ArtBlock")
</div>
<div style="width: 25%; vertical-align: bottom; float: left; clear: left">
    @Html.Partial("ArtBlock")
</div>

This div is repeated four times with four values of the List(Of Integer). That is, if the first index contains a larger value than 100, it should display the first div above and so on...

UPDATE: The inner partial controls are supposed to be accessed from the database on the basis of id from the index of the list.

I have created the functions in the DAL (which is a separate dll) and now only a function call remains.

In the web forms, the inner user controls were bound using the following...

ArtBlock1.Artikel = DataService.Artikel_GetByID(oList(0))

Can anybody help me on what to do to achieve this?


If your parent partial is typed @ModelType List(Of Integer) then iterate over the model to print out the divs. Something like this (excuse syntax errors if any, I use C#, looks like you are using VB)

@foreach(var value in Model)
{
    <div style="width: 25%; vertical-align: bottom; float: left; clear: left">
        @Html.Partial("ArtBlock", value)
    </div>
}

I believe you want to check the value so you can add an if in there.

Update: So assuming your DataService.Artikel_GetByID(oList(0)) returns an Artikel, your parent partial will be typed @ModelType List(Of Artikel). Use the same loop as above, but now your child partial is typed @ModelType Artikel. Your partial action method would return PartialView(artikelList, "nameOfPartial")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜