gpt4 book ai didi

asp.net - asp mvc http get action 以对象为参数

转载 作者:行者123 更新时间:2023-12-04 10:08:07 24 4
gpt4 key购买 nike

在我的 Controller 中,我采取了行动:

[HttpGet]
public ActionResult CreateAdmin(object routeValues = null)
{
//some code
return View();
}

和 http 帖子:
[HttpPost]
public ActionResult CreateAdmin(
string email,
string nameF,
string nameL,
string nameM)
{
if (email == "" || nameF == "" || nameL == "" || nameM == "")
{
return RedirectToAction("CreateAdmin", new
{
error = true,
email = email,
nameF = nameF,
nameL = nameL,
nameM = nameM,
});
}
http get Action 中的可变路由值总是空的。如何正确地将对象作为参数传递给 [http get] Action ?

最佳答案

您不能将对象传递给 GET,而是尝试传递这样的单个值:

[HttpGet]
public ActionResult CreateAdmin(int value1, string value2, string value3)
{
//some code
var obj = new MyObject {property1 = value1; propety2 = value2; property3 = value3};
return View();
}

然后,您可以从应用程序的任何位置传递值,例如:
http://someurl.com/CreateAdmin?valu1=1&value2="hello"&value3="world"

关于asp.net - asp mvc http get action 以对象为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17558025/

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