0

重点是Html.BeginForm函数的“controllerName As String”部分。

的HTML:

根/Views/Home/Therequestform.vbhtml

    <h2>Therequestform</h2>

@Html.BeginForm("Therequest", "Home", method:= FormMethod.Post)

    <fieldset>
        <input type="text" name="ColorName" />
        <input type="submit" name="ColorName_SubmitButton" />
    </fieldset>

控制器:

根/控制器/HomeController.vb

Function Therequestform() As ActionResult

    Return View()

End Function


    <HttpPost()>
    Function Therequest() As ActionResult

        Response.Write("The color you have submitted: " & Request.Form("ColorName"))

        Return View()
    End Function


End Class

问题:

编辑:对视图的调用是在控制器中使用函数“Therequest”对 HTTP POST 方法的请求调用之上完成的。

对 的引用ControllerName已在 的第二部分完成,而在对调用 a 的函数的引用的Html.BeginForm第一部分已完成。Html.BeginFormrequestHTTP POST method

我遇到的问题是,在按下 之后submit button,对函数的调用(在控制器中)没有在设置的位置完成。在按下“提交按钮”后出现以下错误消息:


应用程序中的服务器错误。 未找到视图“请求”或其主视图,或者没有视图引擎支持搜索的位置。搜索了以下位置:

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息: System.InvalidOperationException:未找到视图“请求”或其主视图,或者没有视图引擎支持搜索的位置。搜索了以下位置:

~/Views/Home/Therequest.aspx

~/Views/Home/Therequest.ascx

~/Views/Shared/Therequest.aspx

~/Views/Shared/Therequest.ascx

~/Views/Home/Therequest.cshtml

~/Views/Home/Therequest.vbhtml

~/Views/Shared/Therequest.cshtml

~/Views/Shared/Therequest.vbhtml

源错误:在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。


“搜索”或“呼叫”不在set位置完成。其中通过Html.BeginForm的参数数组,设置了executed函数名称,并且controllerName设置了 - 设置为(root/Controllers/HomeController.vb) - 在第三部分中,方法设置为POST.

问题是,是什么导致不在设定的位置进行呼叫?


使用的工具: VB.NET 2012、MVC 4、Visual Studio 2012、Microsoft SQL Server 2012

4

1 回答 1

0

它正在尝试渲染视图命名Therequest.vbhtml,而您的视图已命名Therequestform.vbhtml

将视图名称更改为Therequest.vbhtml或将控制器名称更改为Therequestform以及引用它的所有位置

于 2012-11-08T01:00:51.593 回答