gpt4 book ai didi

c# - 将附加属性传递给 EditorTemplate

转载 作者:可可西里 更新时间:2023-11-01 08:19:38 24 4
gpt4 key购买 nike

如何将一些额外的属性传递给 EditorTemplate

我想像这样使用它(一种伪代码):

@Html.EditorFor(m => m.ReturnFlight, new { additionalViewData = new { FlightType = FlightType.Return } })
@Html.EditorFor(m => m.OutboundFlight, new { additionalViewData = new { FlightType = FlightType.Outbound } })

飞行模板:

<h1>FLight @Model.FlightNumber</h1>
@if(FlightType == FlightType.Outbound)
{
// Display stuff for outbound flights
}
else if(FlightType == FlightType.Return)
{
// Display stuff for return flights
}
@Form.TextboxFor(m => m.Destination)

最佳答案

您几乎已经掌握了它 - 您可以使用 this overload 以这种方式传递额外的 View 数据.您只需要在您的编辑器模板中使用它。请记住 ViewData 字典中的值在动态 ViewBag 对象中也可用。

@Html.EditorFor(m => m.ReturnFlight, new { FlightType = FlightType.Return })
@Html.EditorFor(m => m.OutboundFlight, new { FlightType = FlightType.Outbound })

飞行模板

<h1>Flight @Model.FlightNumber</h1>
@if(ViewBag.FlightType == FlightType.Outbound)
{
// Display stuff for outbound flights
}
else if(ViewBag.FlightType == FlightType.Return)
{
// Display stuff for return flights
}
@Form.TextboxFor(m => m.Destination)

关于c# - 将附加属性传递给 EditorTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27925093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com