ASP.NET MVC 尝试在提交后重定向到另一个页面

ASP.NET MVC trying to redirect to another page after submit

在视图中,我有以下代码:-

@using(Html.BeginForm("addsurvey","survey")) {

当按下提交按钮时,事件

    [HttpPost]
    public ActionResult addsurvey(Survey oSurvey)
    {

被调用,但页面错误,因为它找不到 addsurvey.aspx 等页面。我没有看错什么。表单所在的页面称为调查。为什么它不能只刷新页面或者我需要

response.redirect("/survey"); 

您的方法必须 return 和 ActionResult。当你使用 return View() 时,通常它是一个 ViewResult,但如果你想重定向到另一个动作,还有另一个 return 类型。只是做:

return RedirectToAction("Index", "survey"); 

(只需将 Index 替换为目标操作即可)

在您可以调用的 addsurvey 操作方法中
View();(项目的View文件夹的controller文件夹中必须有addsurvey.cshtml)
View("actionName") ;(工程的View文件夹下的controller文件夹中必须有actionName.cshtml)或
RedirectoAction("actionName","controllerName") (项目View文件夹的controllerName文件夹中必须有actionName.cshtml)