如何向 CascadingDropDown ServiceMethod 传递附加参数?

发布于 2024-09-25 20:24:42 字数 413 浏览 2 评论 0原文

我有两个链接的 CascadingDropDowns。两者都工作正常。 问题是,在为 DropDwonList 提供值的底层 Web 方法中,我需要读取一个附加参数。设置下拉列表的默认项目需要此参数。

我不知道如何传递该参数或读取它。 我在 Internet 上阅读过有关 ContextKey 属性的信息。但我不知道如何从 WebMethod 访问它。

我尝试通过 HttpContext.Current.Session 访问会话(希望我可以从会话中提取一些参数),但似乎会话对于 WebPage 是不同的代码> 和 WebMethod

所以我在这里迷路了,有什么想法吗?

I have two chained CascadingDropDowns. Both are working fine.
The thing is that in the underlying web methods which are supplying values for DropDwonList I need read one additional parameter. This parameter is needed for setting up the default item for dropdownlist.

I do not know how to pass that parameter or read it.
I've read on the Internet about the ContextKey property. But I do not know how to acces it from the WebMethod.

I've tried to get to the session through HttpContext.Current.Session (hoping that I could extract some parameter from the session) but it seams that the Session is different for the WebPage and WebMethod.

So I am lost here, any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海拔太高太耀眼 2024-10-02 20:24:42

您需要三件事才能使 ContextKey 发挥作用。

  1. 将 CascadingDropDown 上的 UseContextKey 属性设置为 true
  2. 更改 Webmethod 的方法签名以接受 contextKey 参数:

public CascadingDropDownNameValue[] GetDropDownContents(
stringknownCategoryValues, stringcategory, string contextKey) { ... }

注意:参数必须精确大小写。

  1. 使用 JavaScript 设置 ContextKey。 AJAX CascadingDropDown 在 DOM 中公开此属性的 getter/setter:

    document.getElementById('idOfCDDL').set_contextKey('valueyouwant');

HTH。

You need three things to get the ContextKey to work.

  1. Set UseContextKey property on the CascadingDropDown to true
  2. Change the method signature of your webmethod to accept the contextKey parameter:

public CascadingDropDownNameValue[] GetDropDownContents(
string knownCategoryValues, string category, string contextKey) { ... }

NOTE: The parameter has to be exact casing.

  1. Set the ContextKey using JavaScript. The AJAX CascadingDropDown exposes getter/setter for this property in the DOM:

    document.getElementById('idOfCDDL').set_contextKey('valueyouwant');

HTH.

妖妓 2024-10-02 20:24:42

传递附加参数
有时,为组合框提供 JSON 的操作方法可能需要额外的参数。以下是将它们传递给您的操作的方法:
复制将附加参数传递给操作方法

function onComboBoxDataBinding(e) {
    e.data = $.extend({}, e.data, { customParam: "customValue"});
}

Passing Additional arguments
Sometimes the action method which provides the JSON for the combobox may need additional arguments. Here is how to pass them to your action:
CopyPassing additional arguments to the action method

function onComboBoxDataBinding(e) {
    e.data = $.extend({}, e.data, { customParam: "customValue"});
}
鲸落 2024-10-02 20:24:42

在您的 .cs 文件中写入:

cascadingdropdown1.contextKey=<parameter you need>

然后在 Web 方法中使用该 contextKey

In your .cs file write:

cascadingdropdown1.contextKey=<parameter you need>

Then in the web method use that contextKey

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文