ASP.NET MVC表单\控制器路由问题

时间:2022-06-26 17:12:50

I'm a bit new to MVC and have no idea why following issue happening. According to tutorial we can handle form posts by this code:

我对MVC有点新意,不知道为什么会发生以下问题。根据教程,我们可以通过以下代码处理表单帖子:

View:

<form action = "/learning/Goto" method="GET">
        <input type="text"name="gotoUrl"/>
        <input type="submit" name="Goto"/>
</form>    

where Learning is Controller and goto is method as I understood.

学习是控制器和goto是我理解的方法。

Controller:

 public ActionResult Goto(string gotoUrl)
 {
      return Redirect(gotoUrl);
 }

I have a question: all I did according to the tutorial video and it worked in the video. However I have some trouble.

我有一个问题:我根据教程视频所做的一切都在视频中工作。不过我有点麻烦。

In my view I have warning: "Path E:\Programming\MVC_Learning\learning not found" in the following line:

在我看来,我有警告:“路径E:\编程\ MVC_Learning \学习未找到”,如下所示:

<form action = "/learning/Goto" method="GET">

I think that need to setup path to Controller folder. But what I don't understand the most the fact that it works and really redirect to input address but only in this form: "http:// mysite.net". If I write mysite.net I get exception HTTP Error 404.0 - Not Found

我认为需要设置Controller文件夹的路径。但是我最不了解的事实是它工作并且真正重定向到输入地址但只有这种形式:“http:// mysite.net”。如果我写mysite.net我得到异常HTTP错误404.0 - 未找到

Requested URL http://localhost:64074/learning/mysite.net Physical Path E:\Programming\C_SHARP\MVC_Learning\MVC_Learning\learning\mysite.net

请求的URL http:// localhost:64074 / learning / mysite.net物理路径E:\ Programming \ C_SHARP \ MVC_Learning \ MVC_Learning \ learning \ mysite.net

So could somebody explain me following: 1. Why it works with http but does not work without? 2. Why I get warning on

那么有人可以解释我:1。为什么它适用于http,但没有工作? 2.为什么我会收到警告

<form action = "/learning/Goto" method="GET">

?

1 个解决方案

#1


0  

Your controller action url wrong, Instead of "/learning/Goto" use(Most Preferred way in MVC)

您的控制器操作url错误,而不是“/ learning / Goto”使用(MVC中最喜欢的方式)

<form action = "@Url.Action("Goto","learning")" method="GET">

or just remove "/" and

或者只是删除“/”和

<form action = "learning/Goto" method="GET">

#1


0  

Your controller action url wrong, Instead of "/learning/Goto" use(Most Preferred way in MVC)

您的控制器操作url错误,而不是“/ learning / Goto”使用(MVC中最喜欢的方式)

<form action = "@Url.Action("Goto","learning")" method="GET">

or just remove "/" and

或者只是删除“/”和

<form action = "learning/Goto" method="GET">