gpt4 book ai didi

c# - 来自 JsonResult 的动态 ActionLink?

转载 作者:行者123 更新时间:2023-11-28 16:12:05 25 4
gpt4 key购买 nike

我正在开发 MVC3 应用程序。我认为我有一些逻辑想要转移到我的 Controller 。它根据模型的某些方面动态显示 ActionLink。 Html.ActionLink 的 linkText 和 actionName 参数是唯一不同的地方。我向 Controller 添加了一个方法,该方法将返回一个 JsonResult,其中包含 linkText 和 actionName 的字符串:

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetActionButton(int id)
{
string action = null;
string text = null;

// Snipped stuff that sets action and text

return Json(new
{
buttonAction = action,
buttonText = text
});
}

我可以在哪里调用此方法来使用结果创建链接?

最佳答案

要从 Controller 生成链接,请查看 UrlHelper Methods ,最好使用 Action 来接收正常的 url。在使用 jquery 的客户端上,您可以创建如下链接:

$('<a>').attr('href', data.buttonAction).text(data.buttonText)

关于c# - 来自 JsonResult 的动态 ActionLink?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12571051/

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