我对MVC有点新意,并且不知道为什么会发生以下问题。 根据教程,我们可以通过以下代码处理表单帖子:
查看:
<form action = "/learning/Goto" method="GET">
<input type="text"name="gotoUrl"/>
<input type="submit" name="Goto"/>
</form>
学习是控制器,而goto是我理解的方法。
控制器:
public ActionResult Goto(string gotoUrl)
{
return Redirect(gotoUrl);
}
我有一个问题:我根据教程视频做的所有内容都在视频中工作。但是我遇到了一些麻烦。
在我看来,我有警告: &#34;路径E:\编程\ MVC_Learning \学习未找到&#34;在以下行中:
<form action = "/learning/Goto" method="GET">
我认为需要设置Controller文件夹的路径。但是我最不了解的事实是它的工作原理并且真正重定向到输入地址,但只有这种形式:&#34; http:// mysite.net&#34;。如果我写mysite.net,我会得到例外 HTTP错误404.0 - 未找到
请求的网址 http://localhost:64074/learning/mysite.net 物理路径E:\ Programming \ C_SHARP \ MVC_Learning \ MVC_Learning \ learning \ mysite.net
有人可以解释我: 1.为什么它适用于http,但没有工作? 2.为什么我会收到警告
<form action = "/learning/Goto" method="GET">
答案 0 :(得分:0)
Your controller action url wrong, Instead of "/learning/Goto" use(Most Preferred way in MVC)
<form action = "@Url.Action("Goto","learning")" method="GET">
or just remove "/" and
<form action = "learning/Goto" method="GET">