gpt4 book ai didi

c# - 无法获取 Controller 的输入参数,Ajax.ActionLink

转载 作者:太空宇宙 更新时间:2023-11-03 21:50:26 25 4
gpt4 key购买 nike

我在将数据传递给 MVC3 中的 Controller 时遇到问题

我有一个看起来像这样的 View

@Ajax.ActionLink("MyController", "Myfunction", new {id =item.data},  
new AjaxOptions
{
UpdateTargetId = "myDiv",
InsertionMode = InsertionMode.Replace,
})

<div id="myDiv"> </div>

还有一个看起来像这样的 Controller

       public ActionResult Myfunction(string data)
{
//some code
return PartialView(chart);
}

一切正常,但数据没有进入 Controller (当我设置断点时它为空),当我将鼠标悬停在链接上时,我在地址字段中看到数据。我必须在路由表中做一些调整吗?

欢迎任何意见。

最佳答案

It all kinda works but the data dont get into the controller (its null when i set a breakpoint)


改变这一行:

@Ajax.ActionLink("MyController", "Myfunction", new {id=item.data},

成为:

@Ajax.ActionLink("MyController", "Myfunction", new {data =item.data},

在 POST 中声明的变量名称需要与服务器捕获的变量名称相匹配,换句话说,您的 Controller Action 方法 需要一个参数 data 并且它会被传递 id

关于c# - 无法获取 Controller 的输入参数,Ajax.ActionLink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14836863/

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