我在旧视图中创建了一个新视图创建按钮。我无法从“行动”或“网址”中打开新视图。
Controller: HomeController
OlderView: Index (View/Home/Index.cshtml)
Action: Success
NewView: Success (View/Home/Success.cshtml)
Index.cshtml:
<input type="button" value="Download" onclick="location.href='@Url.Action("Success", "Home")'" />
HomeController中:
[HttpPost]
public ActionResult Success()
{
//return View(); //this also doesn't work
return View("Success");
}
Success.cshtml:
@{
ViewBag.Title = "Success";
}
<h2>Your transaction has been completed successfully.</h2>
如果我直接从网址:http://xxx.xxx.x.xx:xxxx/Home/Success尝试,则会抛出以下错误
描述:HTTP 404.您正在查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。
请求的网址:/ Home / Success
版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.6.1069.1
有人能告诉我这里我缺少什么吗?我需要在任何地方注册视图吗?
答案 0 :(得分:0)
您正在调用视图意味着请求是获取请求,但您将视图写为httpPost ... 因此,将操作更改为HttpGet 要么 通过按钮单击或任何其他发布操作来呼叫...