gpt4 book ai didi

c# - 如何在 MVC5 中返回带有查询字符串参数的 View ?

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

非常基础,但不确定如何去做,因为我是 mvc 的新手。

我必须根据 if 条件返回一个 View 。

如果为真,我应该返回一个带有 guid 值作为查询字符串参数的 View 别的返回不同的 View 。

public ActionResult Act(Guid approvalCode)
{
bool result = businessProvider.CheckLinkValidity(approvalCode);
if (result == true)
{
return View("Act"); //here i need to pass approvalcode as querystring param
//want to do like
//return View("Act"+"?code="+approvalcode)
}
return View("LinkExpiredView");
}

我需要像这样渲染 View :

~\ResetController\Act?code=someguidvalue

最佳答案

我其实不明白你为什么需要查询字符串。

没有它你可以这样做:

return View("Act", new { code = "your-guid" });

如果您仍然需要它,可以使用 RedirectToAction 方法之一:

return RedirectToAction("Act", new { code = "your-guid" });

关于c# - 如何在 MVC5 中返回带有查询字符串参数的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38451262/

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