gpt4 book ai didi

c# - mvc3 RedirectToAction

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

为什么这不起作用。当我在我的 Create 方法中重定向时,它一直告诉我编辑需要一个 EditStudyModel。重定向应该执行 get,对吗?

    public ViewResult Create()
{
var createStudyModel = new CreateStudyModel();
return View(createStudyModel);
}

[HttpPost]
public ActionResult Create(CreateStudyModel createStudyModel)
{
try
{
//TODO: Send CreateStudyCommand
return RedirectToAction("Edit", new { scientificStudyId = new Guid("{1C965285-788A-4B67-9894-3D0D46949F11}") });
}
catch
{
return View(createStudyModel);
}
}

[GET("ScientificStudy/Create/{scientificStudyId}")]
public ActionResult Edit(Guid scientificStudyId)
{
//TODO: Query real model
var model = new EditStudyModel() {StudyNr = "T01", StudyName = "Test"};
return View(model);
}

[HttpPost]
public ActionResult Edit(EditStudyModel editStudyModel)
{
try
{
//TODO: Send UpdateStudyCommand
return RedirectToAction(""); //TODO: Terug naar Studie lijst
}
catch
{
return View(editStudyModel);
}
}

最佳答案

您正在返回一个带有 URL 作为字符串的重定向, Controller 无法解析 GUID 并将其转换回 guid 对象,因此它无法解析要使用的正确方法签名。将其更改为:

return RedirectToAction("Edit", new { scientificStudyId = "{1C965285-788A-4B67-9894-3D0D46949F11}" });

public ActionResult Edit(string scientificStudyId)

关于c# - mvc3 RedirectToAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6525662/

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