访问View时出现HTTP 404错误的MVC4程序 [英] MVC4 program having HTTP 404 error when accessing a View

查看:95
本文介绍了访问View时出现HTTP 404错误的MVC4程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的新人。我已经建立了一个MVC4模型:Customer.cs,ID,Code和Amt在类结构中。



我收到错误:

'/'应用程序中的服务器错误。 

无法找到资源。
描述:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。

请求的网址:/主页/输入







CustomerController.vb

  Imports  Mvc4test.Customer 
命名空间 Mvc4test
公共 CustomerController
继承 System.Web.Mvc.Controller

'
' 获取:/客户

函数索引()作为 ActionResult
返回查看()
结束 功能
功能输出() As ActionResult
Dim Cust1 As Customer = Customer()
Cust1.ID = Convert.ToInt32(Request.Form( id ))
Cust1.Code = Request.Form( code
Cust1.Amt = Convert.ToDouble(Request.Form( amt))
返回查看()
结束 函数
函数输入()作为 ActionResult
Dim Cust0 As Customer = New Customer()
Cust0.ID = Convert.ToInt32(Request.Form( id))
Cust0 .Code = Request.Form( code
Cust0.Amt = Convert.ToDouble (Request.Form( amt))
返回查看()
结束 功能

结束
结束 命名空间



对于每个视图,我都进行了构建。我为每个选择了强类型视图并选择了客户。



Input.vbhtml

 @ ModelType Mvc4test.Customer 

@Code
ViewData( Title)= 输入
结束代码

< center>< h2>输入< / h2 > < / center >
< center>< table>< tr>< td>< br />< br />< ; br />
< h5>客户ID#< / h5 > < / td > < / tr > ; < TR>< TD>
@ Html.TextBox( id< / td > < ; / tr > < tr>< td>< br /> ;
< h5>客户代码< / h5 > < / td > < / tr > < TR>< TD>
@ Html.TextBox( code< / td > < ; / tr > < tr>< td>< br /> ;
< h5>金额< / h5 > < / td > ; < / tr > < /跨度>< TR>< TD>
@ Html.TextBox( amt< / td > < ; / tr > < tr>< td>< br /> ;< br />

< input type = submit value = 输入客户数据 />
< / td > < / tr > < / table > < / center >







Output.vbhtml

 @ ModelType Mvc4test。客户

@Code
ViewData( 标题)= View1
结束代码

< h2> View1 < / h2 >
< div>
ID:@ Html.TextBox( id)< br />
代码:@ Html.TextBox( code)< br />
金额:@ Html.TextBox( amt)< br />

<%如果(Model.Amt> 100
{%>
Priveleged Customer
<%}
else
{%>
普通客户
<%} % >

< / div >

解决方案

您是否可以更具体地解决此问题,因为您提供的是代码,但是,我没有办法知道你的视图在哪里,你是否从控制器生成了你的视图?,检查你的RouteConfig.cs,更具体,没有问题,你正在做的事情。 ..

I am new at MVC. I have set up a MVC4 model: Customer.cs with ID, Code and Amt in a class structure.

I get the error:

Server Error in '/' Application.

The resource cannot be found. 
  Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

 Requested URL: /Home/Input




CustomerController.vb

Imports Mvc4test.Customer
Namespace Mvc4test
    Public Class CustomerController
        Inherits System.Web.Mvc.Controller

        '
        ' GET: /Customer

        Function Index() As ActionResult
            Return View()
        End Function
        Function Output() As ActionResult
            Dim Cust1 As Customer = New Customer()
            Cust1.ID = Convert.ToInt32(Request.Form("id"))
            Cust1.Code = Request.Form("code")
            Cust1.Amt = Convert.ToDouble(Request.Form("amt"))
            Return View()
        End Function
        Function Input() As ActionResult
            Dim Cust0 As Customer = New Customer()
            Cust0.ID = Convert.ToInt32(Request.Form("id"))
            Cust0.Code = Request.Form("code")
            Cust0.Amt = Convert.ToDouble(Request.Form("amt"))
            Return View()
        End Function

    End Class
End Namespace


For each "View" I did a "Build". I selected strong-typed view for each and selected "Customer".

Input.vbhtml

@ModelType Mvc4test.Customer

@Code
    ViewData("Title") = "Input"
End Code

    <center><h2>Input</h2></center>
    <center><table><tr><td><br /><br /><br />
        <h5>Customer ID#</h5></td></tr><tr><td>
        @Html.TextBox("id")</td></tr><tr><td><br />
        <h5>Customer Code</h5></td></tr><tr><td>
        @Html.TextBox("code")</td></tr><tr><td><br />
        <h5>Amount</h5></td></tr><tr><td>
        @Html.TextBox("amt")</td></tr><tr><td><br /><br />

        <input type="submit" value="Input Customer Data" />
    </td></tr></table></center>




Output.vbhtml

@ModelType Mvc4test.Customer

@Code
    ViewData("Title") = "View1"
End Code

<h2>View1</h2>
<div>
            ID: @Html.TextBox("id")<br />
            Code: @Html.TextBox("code")<br />
            Amount: @Html.TextBox("amt")<br />
            
            <% if (Model.Amt > 100)
               { %>
                    Priveleged Customer
            <% }
               else
               { %>
                    Normal Customer
            <%}  %>
            
    </div>

解决方案

Could you be more specific with the issue, because you are giving your code, but, I don´t have any way to know where your Views are, did you generate your views from the controllers?, check your RouteConfig.cs, be more specific, not with the problem, with the things you are doing...


这篇关于访问View时出现HTTP 404错误的MVC4程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆