ASP.NET MVC - 使用模型在另一个视图中使用模型的局部视图

时间:2014-05-15 09:47:33

标签: c# asp.net-mvc razor

我是ASP.NET MVC的新手,我希望对以下问题提出一些建议。

我有一个页面,其中的表单应始终提示用户:

// Create.cshtml

@Html.TextBoxFor(m => m.Name)

但是我希望根据作为查询字符串发送的id显示不同的部分 ?ID = 1

EG。如果id为1,那么我想显示

// _ Attributes1.cshtml

@Html.TextBoxFor(m => m.Size)

如果id为2

// _ Attributes2.cshtml

@Html.TextBoxFor(m => m.Brand)

因此当id为1时,页面应该是:

@Html.TextBoxFor(m => m.Name)
@Html.TextBoxFor(m => m.Size)

我想我的模型会像:

public class ProductModel {
    public string Name { get; set; }
    public Attributes Attributes { get; set; }
}

public class Attributes { }

public class Attributes1 : Attributes {
    public int Size { get; set; }
}
public class Attributes2 : Attributes {
    public string Brand { get; set; }
}

关于如何实现这一目标的任何意见?

0 个答案:

没有答案