gpt4 book ai didi

c# - 唯一起作用的代码是 RedirectToAction 但仍然不是所有代码路径都返回值

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

我已经对错误进行了一些搜索,但结果都与使用 try..catchif 语句有关。在我的例子中,我只是向数据库添加一些信息,然后执行 RedirectToAction 调用,我想因为我在技术上没有调用 return 关键字,所以这是问题,但我应该返回什么以及什么时候我想做的只是重定向?

[Route("AddMTNLoctionNote", Name = "Add Location Note")]
public ActionResult AddMTNLocationNote()
{
using (var db = new JobSightDbContext())
{
var newNote = new MTNAlarmLocationNote()
{
LocationID = int.Parse(Request["LocationID"]),
Note = Request["Note"]
};

db.MTNAlarmLocationNotes.Add(newNote);
db.SaveChanges();
}

RedirectToAction("MTNAlarmDetail", int.Parse(Request["LocationID"]));
}

最佳答案

您需要返回 RedirectToAction() 的结果,而不仅仅是调用方法:

return RedirectToAction("MTNAlarmDetail", int.Parse(Request["LocationID"]));

关于c# - 唯一起作用的代码是 RedirectToAction 但仍然不是所有代码路径都返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40136542/

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