开发者

Partial Views with minor different layouts

I have a list of fees that I want to display in a list for various pages on my website. Depending on the page, there are certain information I want to omit to remove clutter and redundancy.

For example, if I'm just listing every fee in the system, I would want to list the descriptions of the fees, the company, and they site they belong to in each row. Where as, if I am just listing the fees in the company page, I would omit the company name in each row. And again, if I am in the company's site page, I would only list the fee's description.

I was thinking about using partial views and using variables in viewmodels to define if / else statements on when to omit what information. But this became complicated really fast; I was curious if there is a different approach that would be better.

I have looked into Html.RenderAction but the extra html request isn't a viable option.

public class Customer
{
    // has some sites
    public IEnumer开发者_JAVA百科able<Site> Sites { get; set; }
}

public class Site
{
    // sites has some fees
    public IEnumerable<Fee> Fees { get; set; }
}

public class Fee
{
    // descriptions, amount, etc...
}


What do you mean by extra HTML request? renderaction doesn't do another http request if that's what you're thinking ... I think that RenderAction is actually a great solution for this. That way, the view selection logic can be maintained in a controller method

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜