gpt4 book ai didi

c# - Html.Grid 中的复选框回发

转载 作者:行者123 更新时间:2023-11-30 17:17:47 25 4
gpt4 key购买 nike

我有一个由 IList 组成的网格:

@Html.Grid(Model.ExampleList).Columns(c =>
{
c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateRequested)).Named("Date Requested");
c.For(a => a.Comment).Named("Comment");
})

但我想添加一个复选框,它将回发到 Controller 。类似这样的东西:

@using (Html.BeginForm("PostExample", "Home")) 
{
<input type="hidden" name="SomeId" value=@ViewBag.SomeId/>
<input type="hidden" name="AnotherId" value="AnotherId" />
@Html.CheckBox("Complete", Model.Complete, new { onClick = "$(this).parent('form:first').submit();"
});

但我不确定如何组合它们。这样做的最佳方法是什么?任何帮助将不胜感激。

最佳答案

你的问题很不明确。你想在哪里显示这个复选框?在每一行?取决于模型的某些值?如果是,那么您可以使用自定义列,如下所示:

.Columns(c =>
{
c.Custom(
@<text>
<form action="@Url.Action("PostExample", "Home")" method="post">
<input type="hidden" name="SomeId" value="@ViewBag.SomeId" />
<input type="hidden" name="AnotherId" value="AnotherId" />
@Html.CheckBoxFor(x => item.Complete, new { onclick = "$(this).parent('form:first').submit();" })
</form>
</text>
);
})

关于c# - Html.Grid 中的复选框回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6243690/

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