【发布时间】:2015-06-06 19:24:45
【问题描述】:
[HttpPost]
public void insertData(string productid)
{
//insert to db
string uri = this.Url.Link("Default", new { controller = "AddProducts", action = "Index" });
//Response.Redirect(Url.Action("", ""));
}
插入数据库后,我想重定向到 actionResult 方法。我有一个 void 方法,我将它返回为什么?
【问题讨论】:
-
什么意思?如果您想向浏览器返回结果,只需从您自己的方法中返回一个 ActionResult 并确保在其中放置了足够的数据来呈现您的视图。如果要重定向到另一个 URL,请使用新 URL 返回 302
-
我的意思是在 api 控制器内。actionResult 只在 mvc 控制器内工作
标签: c# asp.net-mvc-4 asp.net-web-api