C# MVC 应用程序使用 Kendo 表格 – 传递多个参数

huangapple go评论60阅读模式
英文:

C# MVC application with Kendo grid - passing multiple parameters

问题

我需要从我的Kendo网格数据源发送2个参数到我的控制器。这是我的当前代码的样子:

@(Html.Kendo().Grid<OwnerViewModel>()
    .Name("OwnerGrid")
    .AutoBind(true)
    .Columns(columns =>
    {
        columns.Bound(pl => pl.RecordDate).Width(20).Title("Record Date").Format("{0:MM/dd/yyyy}");
        columns.Bound(pl => pl.Unit).Width(15).Title("Unit");
        columns.Bound(pl => pl.Own_Name).Width(45).Title("Name");
        columns.Bound(pl => pl.Own_Salutation).Width(45).Title("Salutation");
        columns.Bound(pl => pl.Own_MailAddr).Width(45).Title("Mailing Addr");
        columns.Bound(pl => pl.Own_City_St_Zip).Width(45).Title("City,State,Zip");
        columns.Bound(pl => pl.Own_PropAddr).Width(45).Title("Property Address");
    })
    .Pageable()
    .Sortable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(5)
        .Read(read => { read.Action("GetOwnerList", "Owners").Data("{ FileNum: " + @Model.FileNum + " , SecondParam: 'YourSecondValue' }"); })
        )
)

这将发送名为'FileNum'的第一个参数以及名为'SecondParam'的第二个参数到Owners控制器的GetOwnerList方法中。

英文:

I need to send 2 parameters from my Kendo grid datasource to my controller. This is what my current code looks like:

@(Html.Kendo().Grid&lt;OwnerViewModel&gt;()
    .Name(&quot;OwnerGrid&quot;)
    .AutoBind(true)
    .Columns(columns =&gt;
    {
        columns.Bound(pl =&gt; pl.RecordDate).Width(20).Title(&quot;Record Date&quot;).Format(&quot;{0:MM/dd/yyyy}&quot;);
        columns.Bound(pl =&gt; pl.Unit).Width(15).Title(&quot;Unit&quot;);
        columns.Bound(pl =&gt; pl.Own_Name).Width(45).Title(&quot;Name&quot;);
        columns.Bound(pl =&gt; pl.Own_Salutation).Width(45).Title(&quot;Salutation&quot;);
        columns.Bound(pl =&gt; pl.Own_MailAddr).Width(45).Title(&quot;Mailing Addr&quot;);
        columns.Bound(pl =&gt; pl.Own_City_St_Zip).Width(45).Title(&quot;City,State,Zip&quot;);
        columns.Bound(pl =&gt; pl.Own_PropAddr).Width(45).Title(&quot;Property Address&quot;);
    })
    .Pageable()
    .Sortable()
    .DataSource(dataSource =&gt; dataSource
        .Ajax()
        .PageSize(5)
        .Read(read =&gt; { read.Action(&quot;GetOwnerList&quot;, &quot;Owners&quot;).Data(&quot;{ FileNum: &quot; + @Model.FileNum + &quot;}&quot;); })
        )
    )

This will send a single parameter called 'FileNum' to GetOwnerList in the Owners controller. How would I set this up to send a second parameter along with FileNum?

Thank you.

答案1

得分: 1

以下是翻译好的部分:

在我的应用程序中,为了提高可读性,我使用了一个JavaScript函数名称来进行数据调用,如下所示:

        .DataSource(dataSource => dataSource
          .Ajax()
          .PageSize(5)
          .Read(read => read.Action("GetOwnerList", "Owners").Data("ReadOwnerListData"))
        )

然后,在您的JavaScript中:

        function ReadOwnerListData() {
            return {
                FileNum: Json.Serialize(Model.FileNum),
                SecondValue: [这里是第二个值]
            };
        }
英文:

What I have done in my applications for better readability is to use a JavaScript function name in the Data call like so:

    .DataSource(dataSource =&gt; dataSource
      .Ajax()
      .PageSize(5)
      .Read(read =&gt; read.Action(&quot;GetOwnerList&quot;, &quot;Owners&quot;).Data(&quot;ReadOwnerListData&quot;)})
    )

then, in your JavaScript:

    function ReadOwnerListData() {
        return {
            FileNum: Json.Serialize(Model.FileNum),
            SecondValue: [second value here]
        };
    }

huangapple
  • 本文由 发表于 2023年4月6日 23:48:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定