当我需要在视图中使用多个按钮时,我想将新的按钮选项列表传递给模型。
我尝试了多种模型设置,但是由于某种原因,我的代码看不到模型。
查看
@Html.Partial("_PageHeader", new FliteAdmin.ViewModels.PageHeaderViewModel { PageTitle = "Tenant onboarding",
Buttons = new List<FliteAdmin.ViewModels.PageHeaderViewModel> {
ButtonTitle = "Add Tenant",
ButtonAction = "TenantDetails",
ButtonController = "System",
ButtonParameters = new { ID = Guid.Empty }.ToString()
}
})
型号
public class PageHeaderViewModel
{
public string PageTitle { get; set; }
public List<Button> Buttons { get; set; }
}
public class Button
{
public string ButtonTitle { get; set; }
public string ButtonAction { get; set; }
public string ButtonController { get; set; }
public string ButtonParameters { get; set; }
}
我希望能够传递按钮列表。
答案 0 :(得分:0)
已解决
@Html.PartialAsync("_PageHeader", new FliteAdmin.ViewModels.PageHeaderViewModel {
PageTitle = "Tenant onboarding",
Buttons = new List<FliteAdmin.ViewModels.Button>() {
new FliteAdmin.ViewModels.Button() {
ButtonTitle = "Add Tenant",
ButtonAction = "TenantDetails",
ButtonController = "System",
ButtonParameters = new { ID = Guid.Empty }.ToString()
}
}
})
答案 1 :(得分:0)
你好我的同事, 这会解决您的问题吗?
@Html.Partial("_PageHeader",
new WebApplication1.Models.PageHeaderViewModel()
{
PageTitle = "Tenant onboarding",
Buttons = new List<WebApplication1.Models.Button>()
{
new WebApplication1.Models.Button
{
ButtonTitle = "Add Tenant",
ButtonAction = "TenantDetails",
ButtonController = "System",
ButtonParameters = new { ID = Guid.Empty }.ToString()
},
new WebApplication1.Models.Button
{
ButtonTitle = "Add Tenant",
ButtonAction = "TenantDetails",
ButtonController = "System",
ButtonParameters = new { ID = Guid.Empty }.ToString()
},
new WebApplication1.Models.Button
{
ButtonTitle = "Add Tenant",
ButtonAction = "TenantDetails",
ButtonController = "System",
ButtonParameters = new { ID = Guid.Empty }.ToString()
}
}
}
)