单击按钮转到另一个视图 - 未找到视图

Go to another view on button click - view is not found

"Test.cshtml" 从未找到视图。

ERROR: The view 'Test' or its master was not found or no view engine supports the searched locations.
The following locations were searched:

列出的位置中有:

但位置不正确,应该是 "~/Views/SecondGroup/Test/123" ??

ViewOne.cshtml(由 FirstController 生成)

<button onclick= "@("window.location.href ='" + @Url.Action("Test", 
"SecondController", new { id = "123" }) + "'");">
 GO TO ANOTHER VIEW
</button>

第二个控制器

public ActionResult Test(string id)
{           
    return View("Test", id);  // here id = '123'          
}

Test.cshtml

@model String
@{    
   Layout = "~/Views/Shared/_Layout.cshtml";
}
<div> .... </div>

文件夹结构如下:

---Controllers
     --- HomeController
     --- FirstController
     --- SecondController

-- Views
     --- FirstGroup
         --- ViewOne

     --- SecondGroup
         --- Test

为什么从未找到 "Test.cshtml" 视图?

谢谢

在您的 Test(string id) 方法中,您使用的 return View("Test", id); 使用 this overload 因为 idtypestring .

在该重载中,第二个参数是呈现视图时要使用的母版页或模板的名称。

您需要使用 this overload,其中第二个参数是 object(您的模型)。

更改代码以将 string 转换为 object:

public ActionResult Test(string id)
{           
    return View("Test", (object)id);       
}